feat(search): 按作品搜资源时中文作品名在前、原名第二

国内站点按中文名收录、副标题也多写中文名,查询词改为作品名(中文)优先、原名第二;
作品名不含中日韩文字时仍原名在前。仍最多 2 个、按归一化去重,拉丁名在电影上带年份。

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-10-06 15:34:33 +08:00
1 parent 6e71df2769
commit 1845d47d3f
2 files changed
+34 -16

No files matched your search

+14 -7
View File
@@ -204,8 +204,9 @@ const emptyInventory = (entityId: string): InventoryEntry => ({
/**
* 搜资源的查询词(每个站点每个词查一次,最多 2 个,控制对站点的请求数):
* 原名(电影带年份,站点标题多为「原名 年份 …」)+ 译名(与原名归一化后不同才加)。
* 剧集不带年份(各季年份不同)。
* 国内站点按中文名收录、副标题也多写中文名,所以作品名(中文)在前,原名第二(与作品名归一化后不同才加)。
* 拉丁文字的名字在电影上带年份(站点标题多为「原名 年份 …」),只带一个;剧集不带年份(各季年份不同)。
* 作品名不含中日韩文字(没有中文译名)时原名在前。
*/
export function searchTerms(w: {
title: string;
@@ -215,17 +216,23 @@ export function searchTerms(w: {
}): string[] {
const out: string[] = [];
const seen = new Set<string>();
const add = (t: string | null, withYear: boolean) => {
const latin = (s: string | null) => !!s && /^[\p{Script=Latin}\d\s\p{P}\p{S}]+$/u.test(s);
const add = (t: string | null) => {
const s = t?.trim();
if (!s) return;
const n = normalizeTitle(s);
if (!n || seen.has(n)) return;
seen.add(n);
out.push(withYear && w.year ? `${s} ${w.year}` : s);
const withYear = w.movie && !!w.year && latin(s) && !out.some(latin);
out.push(withYear ? `${s} ${w.year}` : s);
};
const latin = (s: string | null) => !!s && /^[\p{Script=Latin}\d\s\p{P}\p{S}]+$/u.test(s);
add(w.originalTitle, w.movie && latin(w.originalTitle));
add(w.title, w.movie && latin(w.title) && out.length === 0);
if (/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/u.test(w.title)) {
add(w.title);
add(w.originalTitle);
} else {
add(w.originalTitle);
add(w.title);
}
return out.slice(0, 2);
}