feat(search): 新增共享中文语义词表(285 词/1303 词根),前端与 API 统一支持中文搜索并优化相关性排序

This commit is contained in:
sgp
2026-11-04 22:24:33 +08:00
parent 373e76218b
commit d95d2cccf2
10 changed files with 2156 additions and 31 deletions
+13 -3
View File
@@ -613,9 +613,19 @@ const HGB_UI = (function () {
}
const q = builtinState.search;
if (!q) return list;
// 同时匹配名称与 id(id 可能带库前缀)
return list.filter(i =>
i.name.toLowerCase().includes(q) || i.id.toLowerCase().includes(q));
// 名称 / id / 中文分类 / 中文语义词根(由 js/data/cn-tags.js 提供),按相关性排序
const ql = String(q).trim().toLowerCase();
const roots = HGB_IconLib.expandKeyword ? HGB_IconLib.expandKeyword(ql) : [ql];
if (!HGB_IconLib.scoreIcon) {
return list.filter(i => i.name.toLowerCase().includes(ql) || i.id.toLowerCase().includes(ql));
}
const scored = [];
for (const i of list) {
const sc = HGB_IconLib.scoreIcon(i, ql, roots);
if (sc >= 0) scored.push({ i, sc });
}
scored.sort((a, b) => a.sc - b.sc);
return scored.map(x => x.i);
}
function renderBuiltinGrid(append) {