jackwener/OpenCLI · warning · EmptyResultError

wikidata search: No Wikidata items matched "${query}" in lan

Error message

wikidata search: No Wikidata items matched "${query}" in language "${language}".

What it means

The wikidata search command calls wbsearchentities and requires a non-empty body.search array. When Wikidata returns zero matches for the query in the requested language, an EmptyResultError is thrown with this message. This is a 'no results' condition, not a failure of the request itself.

Source

Thrown at clis/wikidata/search.js:35

    args: [
        { name: 'query', positional: true, required: true, help: 'Search keyword (label / alias)' },
        { name: 'language', default: 'en', help: 'Search & display language (ISO 639, e.g. en, fr, zh)' },
        { name: 'limit', type: 'int', default: 20, help: 'Max items (1-50)' },
    ],
    columns: ['rank', 'qid', 'label', 'description', 'matchType', 'matchText', 'url'],
    func: async (args) => {
        const query = requireString(args.query, 'query');
        const language = requireLanguage(args.language);
        const limit = requireBoundedInt(args.limit, 20, 50);
        const url = `${WIKIDATA_BASE}/w/api.php?action=wbsearchentities`
            + `&search=${encodeURIComponent(query)}`
            + `&language=${encodeURIComponent(language)}`
            + `&uselang=${encodeURIComponent(language)}`
            + `&type=item&format=json&limit=${limit}&origin=*`;
        const body = await wikidataFetch(url, 'wikidata search');
        const list = Array.isArray(body?.search) ? body.search : [];
        if (!list.length) {
            throw new EmptyResultError('wikidata search', `No Wikidata items matched "${query}" in language "${language}".`);
        }
        return list.slice(0, limit).map((item, i) => {
            const qid = String(item?.id ?? '').trim();
            return {
                rank: i + 1,
                qid,
                label: typeof item?.label === 'string' ? item.label : null,
                description: typeof item?.description === 'string' ? item.description : null,
                matchType: typeof item?.match?.type === 'string' ? item.match.type : null,
                matchText: typeof item?.match?.text === 'string' ? item.match.text : null,
                url: qid ? `${WIKIDATA_BASE}/wiki/${qid}` : '',
            };
        });
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry with a broader or corrected query string
  2. Search with --language en, which has the broadest label coverage, then inspect labels in other languages
  3. Check the term exists at wikidata.org via the web search UI
  4. If looking for properties or lexemes, note the adapter's search returns Q-ID items by default

Example fix

// before
await runCli(['wikidata', 'search', 'Duglas Adams', '--language', 'fr']);
// after
await runCli(['wikidata', 'search', 'Douglas Adams', '--language', 'en']);
Defensive patterns

Strategy: fallback

Validate before calling

if (!query || !query.trim()) throw new Error('search query must be non-empty');
if (language && !/^[a-z]{2,3}(-[a-z]{2,8})?$/.test(language)) throw new Error('bad language code');

Try / catch

try {
    const results = await runCli(['wikidata', 'search', query, '--language', lang]);
} catch (e) {
    if (/No Wikidata items matched/.test(e.message)) {
        // fall back to English or a broader query
        results = await runCli(['wikidata', 'search', query, '--language', 'en']);
    } else throw e;
}

Prevention

When it happens

Trigger: Calling `wikidata search <query> --language <lang>` where the wbsearchentities response's search array is empty — misspelled terms, very obscure subjects, or terms with no labels in the requested language.

Common situations: Searching in a language where the concept has no Wikidata label (e.g. a rare term in 'zh-hans'); misspelling the search term; searching for a property/lexeme concept that search (item-only by default) cannot find.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/c4af0dbcc5a05022. Report an issue: GitHub.