diff --git a/src/shared/ehentai/normalize-tag.ts b/src/shared/ehentai/normalize-tag.ts index 5620cd00..ee724d83 100644 --- a/src/shared/ehentai/normalize-tag.ts +++ b/src/shared/ehentai/normalize-tag.ts @@ -102,7 +102,8 @@ export async function normalizeTag( const candidates = source.filter((t) => t.raw === raw); if (ns) { match = candidates.find((t) => t.namespace === ns); - } else if (candidates.length === 1 && source.length < 10) { + } + if (match == null && candidates.length === 1 && source.length < 10) { // 只有一个结果,且原始结果完整 match = candidates[0]; } diff --git a/src/shared/ehentai/suggest-tag.ts b/src/shared/ehentai/suggest-tag.ts index 0c714ece..ec3271fc 100644 --- a/src/shared/ehentai/suggest-tag.ts +++ b/src/shared/ehentai/suggest-tag.ts @@ -92,6 +92,7 @@ export async function suggestTag(ns: NamespaceName | undefined, raw: string, exa (t.master && t.master.raw === raw && ns === t.master.namespace), ) == null ) { + // 没有正确匹配时升级为精确搜索 const exactResult = await suggestTag(ns, raw, true); if (exactResult.length !== 0) return exactResult; } diff --git a/src/tool/commands/tag/check.ts b/src/tool/commands/tag/check.ts index db52a258..ed26ead5 100644 --- a/src/tool/commands/tag/check.ts +++ b/src/tool/commands/tag/check.ts @@ -33,7 +33,7 @@ command } } } else { - const result = (await normalizeTag(namespace, raw)) ?? (await normalizeTag(undefined, raw)); + const result = await normalizeTag(namespace, raw); if (result) { print(result); found = true; diff --git a/src/tool/commands/tag/search.ts b/src/tool/commands/tag/search.ts index 91ec8df9..bd059924 100644 --- a/src/tool/commands/tag/search.ts +++ b/src/tool/commands/tag/search.ts @@ -4,10 +4,11 @@ import { command, parseTag, formatTag } from './command.js'; command .command('search <[namespace:]tag>') + .option('-e, --exact', '精确搜索') .description('搜索标签') - .action(async (tag: string) => { + .action(async (tag, { exact }) => { const [namespace, raw] = parseTag(tag); - const result = await suggestTag(namespace, raw); + const result = await suggestTag(namespace, raw, exact); if (result.length === 0) { console.error('未找到相应标签'); } else {