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

Prefix search doesn''t work in some cases. #413

Closed
JulianKK opened this issue Aug 30, 2019 · 2 comments
Closed

Prefix search doesn''t work in some cases. #413

JulianKK opened this issue Aug 30, 2019 · 2 comments

Comments

@JulianKK
Copy link

JulianKK commented Aug 30, 2019

There is a document in my index with the title 'Reconnaissance' and when I try to find it, using prefix. It is found from 'r' to 'reconnaiss' but if I try to find 'reconnaissa' nothing is found. Did I missed something?

Same thing with vandalism => from vandal on there is no result anymore

@hidmic
Copy link

hidmic commented Sep 13, 2019

Same issue here, see ticket. It happens both with and without wildcards.

@olivernn
Copy link
Owner

olivernn commented Oct 5, 2019

This sounds likely to be caused by stemming.

> lunr.stemmer(new lunr.Token("reconnaissance")).toString()
'reconnaiss'

That is, only the text 'reconnaiss' is actually indexed by Lunr. This works when performing non prefix search because the search term will also be stemmed before doing the lookup. Stemming is not possible when doing a prefix search, and so once you have a prefix longer than the stemmed word stored in the index there will be no matches.

You can disable stemming for the index, or alternatively perform both a prefix search and a non-prefix search together.

idx.query(function (query) {
  // prefix search, no boost
  query.term("reconnaiss", { wildcard: lunr.Query.wildcard.TRAILING, boost: 1 })

  // 'exact' match, boosted
  query.term("reconnaiss", { boost: 10 })
})

The above will combine both a prefix search with an exact search, exact matches will typically rank higher given the boosts.

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

3 participants