feat(docs): 支持多词分词模糊检索与匹配依据片段高亮展示

- 增强 `src/domains/docs/tools.ts` 的搜索评分引擎,支持自然多词组合与分词(如 "员工 手机"、"报销 审批")
- 扩充正文段落、请求参数表格、返回报文 JSON 与 CURL 示例的多层级深度匹配
- 新增 `matchReason` 匹配依据与上下文片段(Snippet)生成,在 CLI 表格及 JSON 结果中清晰呈现命中理由
- 完善 `src/domains/docs/docs.test.ts` 跨正文分词检索测试用例
This commit is contained in:
gitea committed 2026-11-16 16:42:43 +08:00
1 parent 9cf247fe45
commit 6ba748e531
4 files changed
+157 -34

No files matched your search

+19 -7
View File
@@ -182,6 +182,7 @@ export async function handleDocsCommand(
path: item.path,
url: item.url,
permalink: item.permalink,
matchReason: item.matchReason || undefined,
}));
return {
stdout: printJson(
@@ -208,14 +209,25 @@ export async function handleDocsCommand(
};
}
const rows = searchRes.items.map((item) => [
item.method || "DOC",
item.path || item.url,
item.title,
item.category,
]);
const hasKeyword = Boolean(keyword);
const headers = hasKeyword
? ["Method", "Path / URL", "标题", "分类", "匹配依据"]
: ["Method", "Path / URL", "标题", "分类"];
const table = printTable(["Method", "Path / URL", "标题", "分类"], rows);
const rows = searchRes.items.map((item) => {
const base = [
item.method || "DOC",
item.path || item.url,
item.title,
item.category,
];
if (hasKeyword) {
base.push(item.matchReason || "-");
}
return base;
});
const table = printTable(headers, rows);
const filterDesc = [
keyword ? `关键词: '${keyword}'` : "",
category ? `分类: '${category}'` : "",