Elasticlunr.js 支持其他语言 V0.9.5

之前一直没有处理其他的语言的需求,所以没有测试elasticlunr.js对于其他的语言的支持。多亏了Github的网友,帮忙发现了elasticlunr.js对于其他语言支持的问题。

昨天,elasticlunr.js发布了V0.9.5版本,利用lunr-languages已有的对于其他语言的支持功能,使得elasticlunr.js能够支持目前所有的lunr-languages支持的语言。

目前lunr-languages支持的语言包括:
* German
* French
* Spanish
* Italian
* Japanese
* Dutch
* Danish
* Portuguese
* Finnish
* Romanian
* Hungarian
* Russian
* Norwegian

各位小伙伴们,还希望大家能够帮忙传播,帮忙点赞哦 elasticlunr.js

How to use elasticlunr.js in other languages

Default supported language of elasticlunr.js is English, if you want to use elasticlunr.js to index other language documents, then you need to use elasticlunr.js combined with lunr-languages.

Other languages example in Browser

Suppose you are using elasticlunr.js in browser for other languages, you could download the corresponding language support from lunr-languages, then include the scripts as:

<script src="lunr.stemmer.support.js">script>
<script src="lunr.de.js">script>

then, you could use elasticlunr.js as normal:

var index = elasticlunr(function () {
    // use the language (de)
    this.use(elasticlunr.de);
    // then, the normal elasticlunr index initialization
    this.addField('title')
    this.addField('body')
});

Pay attention to the special code:

    this.use(elasticlunr.de);

If you are using other language, such as es(Spanish), download the corresponding lunr.es.js file and lunr.stemmer.support.js, and change the above line to:

    this.use(elasticlunr.es);

Other languages example in Node.js

Suppose you are using elasticlunr.js in Node.js for other languages, you could download the corresponding language support from lunr-languages, put the files lunr.es.js file and lunr.stemmer.support.js in your project, then in your Node.js module, use elasticlunr.js as:

var elasticlunr = require('elasticlunr');
require('./lunr.stemmer.support.js')(elasticlunr);
require('./lunr.de.js')(elasticlunr);

var index = elasticlunr(function () {
    // use the language (de)
    this.use(elasticlunr.de);
    // then, the normal elasticlunr index initialization
    this.addField('title')
    this.addField('body')
});

For more details, please go to lunr-languages.

你可能感兴趣的:(Nodejs)