@
subframe75361 就还是 minisearch ,我说的研究的意思是指看了下 vitepress 源码怎么使用 minisearch 的,最后发现是分词的配置问题,在 vitepress 里像下边这样配置就可以了
```js
...
export default defineConfig({
...
themeConfig: {
search: {
options: {
miniSearch: {
options: {
tokenize: (term) => {
if (typeof term === 'string') term = term.toLowerCase();
// @
ts-ignore const segmenter = Intl.Segmenter && new Intl.Segmenter("zh", { granularity: "word" });
if (!segmenter) return [term];
const tokens = [];
for (const seg of segmenter.segment(term)) {
// @
ts-ignore tokens.push(seg.segment);
}
return tokens;
},
},
searchOptions: {
combineWith: 'AND', // important for search chinese
processTerm: (term) => {
if (typeof term === 'string') term = term.toLowerCase();
// @
ts-ignore const segmenter = Intl.Segmenter && new Intl.Segmenter("zh", { granularity: "word" });
if (!segmenter) return term;
const tokens = [];
for (const seg of segmenter.segment(term)) {
// @
ts-ignore tokens.push(seg.segment);
}
return tokens;
},
},
},
},
},
},
...
});
```