From 7b19f59409007335e04af38c9df1f12ae93a11a1 Mon Sep 17 00:00:00 2001 From: R2m1liA <15258427350@163.com> Date: Mon, 10 Nov 2025 17:26:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4=E7=AD=9B=E9=80=89?= =?UTF-8?q?=E6=9D=A1=E7=9B=AE=E6=8E=92=E5=BA=8F=E6=9D=83=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 以搜索条目匹配程度为标准排序 - 移除拼音支持 --- app/utils/fuzzyFilter.ts | 38 +++++--------------------------------- package.json | 1 - pnpm-lock.yaml | 8 -------- 3 files changed, 5 insertions(+), 42 deletions(-) diff --git a/app/utils/fuzzyFilter.ts b/app/utils/fuzzyFilter.ts index 3a88391..942367f 100644 --- a/app/utils/fuzzyFilter.ts +++ b/app/utils/fuzzyFilter.ts @@ -26,25 +26,12 @@ export function fuzzyMatch( source: T[], options: FuzzyFilterOptions ): 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( .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) => diff --git a/package.json b/package.json index 9440f07..00f7eb4 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,6 @@ "meilisearch": "^0.53.0", "nuxt": "^4.0.3", "nuxt-directus": "5.7.0", - "pinyin-pro": "^3.27.0", "sass": "^1.90.0", "sharp": "^0.34.3", "vue": "^3.5.18", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 19778d8..eae14c2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -62,9 +62,6 @@ importers: nuxt-directus: specifier: 5.7.0 version: 5.7.0(magicast@0.3.5) - pinyin-pro: - specifier: ^3.27.0 - version: 3.27.0 sass: specifier: ^1.90.0 version: 1.92.1 @@ -4402,9 +4399,6 @@ packages: typescript: optional: true - pinyin-pro@3.27.0: - resolution: {integrity: sha512-Osdgjwe7Rm17N2paDMM47yW+jUIUH3+0RGo8QP39ZTLpTaJVDK0T58hOLaMQJbcMmAebVuK2ePunTEVEx1clNQ==} - pkg-types@1.3.1: resolution: {integrity: sha512-/Jm5M4RvtBFVkKWRu2BLUTNP8/M2a+UwuAX+ae4770q1qVGtfjG+WTCupoZixokjmHiry8uI+dlY8KXYV5HVVQ==} @@ -10624,8 +10618,6 @@ snapshots: optionalDependencies: typescript: 5.9.2 - pinyin-pro@3.27.0: {} - pkg-types@1.3.1: dependencies: confbox: 0.1.8 -- 2.49.0