Language Support

Lunr has full support for the indexing and searching of documents in English. If your documents are in another language, you need to install the Lunr Languages plugin to get the best search results. Currently the following languages are supported:

  • German
  • Danish
  • Spanish
  • Finnish
  • French
  • Hungarian
  • Italian
  • Japanese
  • Dutch
  • Norwegian
  • Portuguese
  • Romanian
  • Russian
  • Thai

Installing

First, install the lunr-languages package:

$ npm install lunr-languages

Next, load the lunr.stemmer.support plugin and the appropriate language extension, which is identified by the ISO 639-1 language code.

The following example sets up the French language plugin and uses it when defining an index:

var lunr = require("lunr")
require("lunr-languages/lunr.stemmer.support")(lunr)
require("lunr-languages/lunr.fr")(lunr)

var idx = lunr(function () {
  this.use(lunr.fr)
  this.ref('id')
  this.field('text')

  this.add({
    id: 1,
    text: "Ceci n'est pas une pipe"
  })
})

idx.search('pipe')

Multi-Language Content

If you have documents in more than one language, it is still possible to index them together by combining two or more language extensions using the lunr.multiLanguage plugin, part of lunr-languages package.

The following example sets up an index with support for both English and German:

var lunr = require("lunr")
require("lunr-languages/lunr.stemmer.support")(lunr)
require('lunr-languages/lunr.multi')(lunr)
require("lunr-languages/lunr.de")(lunr)

var idx = lunr(function () {
  this.use(lunr.multiLanguage('en', 'de'))
})