Skip to content

Commit

Permalink
fix: 搜索标签
Browse files Browse the repository at this point in the history
  • Loading branch information
OpportunityLiu committed Apr 23, 2024
1 parent cc4df01 commit 540821e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/shared/ehentai/normalize-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
1 change: 1 addition & 0 deletions src/shared/ehentai/suggest-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tool/commands/tag/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/tool/commands/tag/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 540821e

Please sign in to comment.