Raneto部署知識庫平台&支持中文搜索


文檔最后更新時間:2019年3月14日11:51:13

環境

操作系統:Centos 7

更新軟件包

[root@localhost]# yum upgrade
[root@localhost]# yum update

部署 Raneto 知識庫平台

安裝 Node 環境

安裝 node 管理工具

[root@localhost]# curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
[root@localhost]# source ~/.bash_profile

查看 node 列表

[root@localhost]# nvm list-remote

安裝需要的Node版本

[root@localhost]# nvm install v0.10.12

使用 淘寶NPM

[root@localhost]# npm config set registry http://registry.npm.taobao.org/

git 使用代理設置,大陸地區訪問git受限,故科學上網

[root@localhost]# gti config --global http.proxy socks5://10.1.22.78:1080
[root@localhost]# git config --global https.proxy socks5://10.1.22.78:1080

安裝Raneto 知識庫平台

[root@localhost]# git clone https://github.com/gilbitron/Raneto.git && cd Raneto && npm install && npm run gulp

Raneto 中文搜索支持

備份其lunr

cd Raneto
mv  ./node_modules/lunr  node_modules/lunr_bak

下載支持中文搜索的lunr包,重命名為lunr文件夾

cd  Raneto/node_modules
git clone https://github.com/codepiano/lunr.js && mv lunr.js lunr

復制支持中文搜索的lunr.js文件到Raneto/app/core目錄下

cp  Raneto/node_modules/lunr/lunr.js  Raneto/app/core/

修改Raneto/app/core/search.js文件

直接引用 支持中文搜索的 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;
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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM