Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples how to customize lunr #230

Closed
anatoly314 opened this issue Aug 29, 2016 · 2 comments
Closed

Examples how to customize lunr #230

anatoly314 opened this issue Aug 29, 2016 · 2 comments

Comments

@anatoly314
Copy link

Hi,
Maybe it's dumb question but I couldn't realize how to add custom tokenizer to lunr, is it possible? Where can I find more advanced examples?

Thank you for great library.

@olivernn
Copy link
Owner

olivernn commented Sep 5, 2016

It is possible, but probably poorly documented. The feature was requested a long time ago, but I only added it very recently. There is a simple example in the tests that might help.

The tokeniser function must split an object (probably a string, but it should handle other object types in some way also) into strings. You can look at the default tokeniser for some inspiration.

Once you have defined your tokeniser you must associate it with the index, like so:

var myCustomTokeniser = function () { /* implementation goes here */ }
lunr.tokenizer.registerFunction(fn, 'myCustomTokeniser') // allow the index to be serialised

// when creating the index
var idx = lunr(function () {
  this.tokenizer(myCustomTokenizer)
})

Alternatively the default tokeniser allows you to change what it considers white space to split on, if that is all you need to change.

Let me know if you have any other questions.

@olivernn
Copy link
Owner

Closing. More documentation on customising lunr is also available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants