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

猜你喜欢

转载自www.cnblogs.com/itwo/p/10534642.html