From 540821ed5c1ae613f85ec360fe38d3c6dcfc7a7f Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Wed, 24 Apr 2024 01:05:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=90=9C=E7=B4=A2=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/shared/ehentai/normalize-tag.ts | 3 ++- src/shared/ehentai/suggest-tag.ts | 1 + src/tool/commands/tag/check.ts | 2 +- src/tool/commands/tag/search.ts | 5 +++-- 4 files changed, 7 insertions(+), 4 deletions(-) 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 {