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

Search doesn't work with "a" or "i" #233

Closed
imjoeco opened this issue Sep 9, 2016 · 2 comments
Closed

Search doesn't work with "a" or "i" #233

imjoeco opened this issue Sep 9, 2016 · 2 comments

Comments

@imjoeco
Copy link

imjoeco commented Sep 9, 2016

As the title suggests, Lunr doesn't work with a search query of "a" or "i". Returns empty array.

Demo here:
https://jsfiddle.net/6qtmh2g7/

@olivernn
Copy link
Owner

The problem you are having is that both 'a' and 'i' are stop words and so are filtered out by lunr.stopWordFilter.

The stop word filter is run as part of indexing and querying, this is because those words are very common and add little to differentiate between documents, almost every English document will contain these words.

If you really want to search for 'a' or 'i' (or any other word that by default lunr considers a stop word) you have two options:

  1. Remove the stop word filter
  2. Specify a custom stop word filter

Removing the stop word filter is simple, but will likely have a negative impact on the relevance scores of searches and will definitely increase the size of the index.

var idx = lunr(function () {
   // normal index definition
  this.pipeline.remove(lunr.stopWordFilter)
})

Alternativley you can create your own stop word filter, the default stop word filter is built using lunr.generateStopWordFilter and you can see an example in the lunr.stopWordFilter file, linked above, to see how to use it. Lets say you created your own stop word filter and called it myStopWordFilter you would then use it in your index like this:

var idx = lunr(function () {
  // normal index definition
  this.pipeline.after(lunr.stopWordFilter, myStopWordFilter)
  this.pipeline.remove(lunr.stopWordFilter)
})

@imjoeco
Copy link
Author

imjoeco commented Sep 14, 2016

Thanks Oliver, that makes total sense. I'll close this as a non-issue.

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