搜索聚合规则增强

This commit is contained in:
mtvpls
2026-01-05 20:42:45 +08:00
parent 9b3de638a1
commit f1a295cd75
2 changed files with 24 additions and 6 deletions
+11 -2
View File
@@ -212,14 +212,23 @@ function SearchPageClient() {
return order === 'asc' ? aNum - bNum : bNum - aNum;
};
// 规范化标题用于聚合(去除特殊符号、括号、空格和全角空格)
const normalizeTitle = (title: string) => {
return title
.replace(/[\s\u3000]/g, '') // 去除空格和全角空格
.replace(/[()()[\]【】{}「」『』<>《》]/g, '') // 去除各种括号
.replace(/[^\w\u4e00-\u9fa5]/g, ''); // 去除特殊符号,保留字母、数字、下划线和中文
};
// 聚合后的结果(按标题和年份分组)
const aggregatedResults = useMemo(() => {
const map = new Map<string, SearchResult[]>();
const keyOrder: string[] = []; // 记录键出现的顺序
searchResults.forEach((item) => {
// 使用 title + year + type 作为键,year 必然存在,但依然兜底 'unknown'
const key = `${item.title.replaceAll(' ', '')}-${item.year || 'unknown'
// 使用规范化后的 title + year + type 作为键,year 必然存在,但依然兜底 'unknown'
const normalizedTitle = normalizeTitle(item.title);
const key = `${normalizedTitle}-${item.year || 'unknown'
}-${item.episodes.length === 1 ? 'movie' : 'tv'}`;
const arr = map.get(key) || [];