搜索内容是否可以忽略大小写
Tricker39 opened this issue · comments
感觉你的这个插件很好用,但是我在使用的时候遇到这样一个问题,在搜索框里面输入的内容并无法过滤文章中的大小写字母。这样感觉会损失效率,你觉得呢?
ok 我记一下,近期会迭代一版 到时候看看怎么支持咱这个功能
看了一下 pagefind.js 里对搜索的处理都会转成小写处理通过 toLowerCase
async search(term, options = {}) {
options = {
verbose: false,
filters: {},
sort: {},
...options,
};
const log = str => { if (options.verbose) console.log(str) };
log(`Starting search on ${this.basePath}`);
let start = Date.now();
let ptr = await this.getPtr();
let filter_only = term === null;
term = term ?? "";
let exact_search = /^\s*".+"\s*$/.test(term);
if (exact_search) {
log(`Running an exact search`);
}
// Strip special characters to match the indexing operation
// TODO: Maybe move regex over the wasm boundary, or otherwise work to match the Rust regex engine
term = term.toLowerCase().trim().replace(/[\.`~!@#\$%\^&\*\(\)\{\}\[\]\\\|:;'",<>\/\?\-]/g, "").replace(/\s{2,}/g, " ").trim();
log(`Normalized search term to ${term}`);
插件今天迭代了一波,优化了一下针对中文内容 的检索 ,可以升级一下,看看使用反馈
(可选) ③: 搜索优化
如果你的文档主要内容是中文,推荐做以下设置,优化一下搜索
在配置中加入 chineseSearchOptimize
方法
import { defineConfig } from 'vitepress'
import { chineseSearchOptimize, pagefindPlugin } from 'vitepress-plugin-pagefind'
export default defineConfig({
lang: 'zh-cn',
vite: {
plugins: [pagefindPlugin({
customSearchQuery: chineseSearchOptimize
})],
},
})
好的,谢谢大佬