fix: 调整筛选条目排序权重
All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m49s

- 以搜索条目匹配程度为标准排序
- 移除拼音支持
This commit is contained in:
2025-11-10 17:26:17 +08:00
parent 9de6ab8799
commit 7b19f59409
3 changed files with 5 additions and 42 deletions

View File

@ -26,25 +26,12 @@ export function fuzzyMatch<T extends object>(
source: T[],
options: FuzzyFilterOptions<T>
): T[] {
const {
keyword,
keys,
threshold = 0.35,
minMatchCharLength = 1,
locale = 'auto',
} = options;
// --- 多语言比较器 ---
const collator = new Intl.Collator(locale === 'auto' ? undefined : locale, {
sensitivity: 'base',
ignorePunctuation: true,
});
const { keyword, keys, threshold = 0.35, minMatchCharLength = 1 } = options;
// --- 文本标准化函数 ---
const normalizeText = (text: string): string => {
const normalizedText = text.normalize('NFKC').toLowerCase().trim();
const translit = transliterateText(normalizedText);
return `${normalizedText} ${translit}`;
return normalizedText;
};
/**
@ -102,29 +89,14 @@ export function fuzzyMatch<T extends object>(
.replace(/\s+/g, '')
.toLowerCase()
.trim();
const translit = transliterateText(normalized);
logger.debug(`${normalized} => ${translit}`);
// 拼接原文 + 转写,提升中外文混合匹配效果
return `${normalized} ${translit}`;
return normalized;
}
return value;
},
sortFn: (a, b) => {
const itemA = a.item as T;
const itemB = b.item as T;
const key = keys[0];
const aValue = itemA[key];
const bValue = itemB[key];
if (typeof aValue === 'string' && typeof bValue === 'string') {
return collator.compare(aValue, bValue);
}
return 0;
},
});
logger.debug('Fuzzy search options:', options);
logger.debug('Fuzzy search keyword:', k);
return fuse.search(k).map((result) => result.item);
const result = fuse.search(k);
return result.map((result) => result.item);
}
return source.filter((item) =>