背景
因業務部門需要在線軟件使用說明文檔,但我們資源不足,故我想找一個開源的知識庫,發現 Raneto不錯,決定使用。
官方文檔相當清晰,部署完成,發布一些文章,啟動項目,交由業務同事測試使用,於是我收到 中文搜索 不支持反饋。查看其配置文件
example/config.default.js
// Support search with extra languages
searchExtraLanguages: ['ru'],在 `Raneto/node_modules/lunr-languages/`列表下並沒有 `lunr.zh.js` 中文搜索支持文件,故此路不通。那就谷歌解決此問題了。
環境
Centos
Raneto 0.16.2
需求
二次開發 Raneto 中文搜索支持
解決
重命名
lunr文件夾
cd Raneto
mv ./node_modules/lunr node_modules/lunr_official
下載
https://github.com/codepiano/lunr.js文件夾並重命名為lunr
cd Raneto/node_modules
git clone https://github.com/codepiano/lunr.js && mv lunr.js lunr
修改
Raneto/app/core/search.js文件
1.復制該文件到 Raneto/app/core/目錄里
cp Raneto/node_modules/lunr/lunr.js Raneto/app/core/
2.直接引用其 https://github.com/codepiano/lunr.js 的 lunr.js 文件,也就是Raneto/app/core/lunr.js,另外,注釋其語言加載配置。
function getLunr (config) {
if (instance === null) {
// instance = require('lunr');
instance = require('./lunr.js');
// require('lunr-languages/lunr.stemmer.support')(instance);
// require('lunr-languages/lunr.multi')(instance);
// config.searchExtraLanguages.forEach(lang =>
// require('lunr-languages/lunr.' + lang)(instance)
// );
}
return instance;
3.注釋默認設置加載的lunr配置
function handler (query, config) {
const contentDir = utils.normalizeDir(path.normalize(config.content_dir));
const documents = glob
.sync(contentDir + '**/*.md')
.map(filePath => contentProcessors.extractDocument(
contentDir, filePath, config.debug
))
.filter(doc => doc !== null);
const lunrInstance = getLunr(config);
const idx = lunrInstance(function () {
// 注釋默認設置加載的lunr配置
// this.use(getStemmers(config));
this.field('title');
this.field('body');
this.ref('id');
documents.forEach((doc) => this.add(doc), this);
});
安裝
nodejieba模塊
npm install --save nodejieba
最后再次啟動,支持中文搜索了
cd Raneto
npm start
