默認主題自帶的搜索, 只會為頁面的標題、h2、h3 以及 tags構建搜索索引。所以盡量將圍繞知識點的關鍵字體現到標題上。而 tags 更為靈活,可以把相關的能想到的關鍵字都配置到 tags 中,以方便搜索。
默認插件介紹 (opens new window)
默認主體配置 (opens new window)
# 通過插件 vuepress-plugin-fulltext-search 實現全文搜索
-
安裝依賴 vuepress-plugin-fulltext-search
yarn add -D vuepress-plugin-fulltext-search
-
修改配置 vi docs/.vuepress/config.js
module.exports = {// ...plugins: ['fulltext-search'],}
搜索效果如下, 展示效果和 algolia 相似
提示
安裝了該依賴后, 后面再用 yarn 安裝其它依賴會報錯,為避免影響其它插件正常使用,我最后決定從系統中移除了該插件
參考文檔 (opens new window)
提示
發現的不足:
沒有提供額外的調整參數, 如最大搜索結果數量等
關鍵詞不高亮顯示
官方文檔 (opens new window)
# 通過插件 vuepress-plugin-flexsearch 實現全文搜索
-
安裝依賴
yarn add -D vuepress-plugin-flexsearch
-
修改配置
// .vuepress/config.jsmodule.exports = {plugins: [['flexsearch'],// other plugins] }
提示
優點:
- 提供了更多的配置項
- 搜索結果高亮顯示
但是按官方文檔沒有配置好對中文分詞的支持,待日后完善。
官方文檔 (opens new window)
搜索效果如下
# 集成第三方免費搜索服務 algolia
https://docsearch.algolia.com/apply/
[外鏈圖片轉存中…(img-3RqMqaai-1701934107943)]