lunr.js: Searching words with ending wildcards returns inconsistent results
For example, on https://olivernn.github.io/moonwalkers/, both pilot and pilot* will return the results I expect. However, module* returns nothing (while module works as I expect).
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 20 (10 by maintainers)
@larskendall without seeing how you set up your index its difficult to say for sure, but that looks like the result of stemming. “critical” stems to “critic” you can test this out with the following snippet:
Further up in this thread there are a couple of suggestions for ways to express searches that will lead to the kind of results it seems you are expecting. An alternative is to disable the stemmer at build time and search time:
I’ve pushed a change that should fix the “duplicate index” error, please try version 2.0.3 and let me know if there are any issues.
Note I believe ^ may cause issues if
queryTermis multiple words as only the last word will get increased priority, does that sound right?@et1421 I’m going to close this issue now, if you can provide more details on the results you were seeing (specifically being able to provide the index) then please re-open this issue and I’ll take a further look.
What I noticed from peoples use case of lunr is that, for typeahead style search, the automatic wildcard could give nice results, as shown on your site. However it would frequently cause unexpected results, just take a look through some of the closed issues.
I was thinking about what the best way to express a query for typeahead search might be, there obviously needs to be a component searching for the beginning of a string, but it should also look for exact matches. Perhaps also allow for some fuzzy matching too?
All of the above are possible with lunr. I would advise looking into the
lunr.Index#querymethod, it is intended to be used for building queries programatically (it is used internally bylunr.Index#search).Below is an example of what I was thinking for typeahead search:
The only slight wrinkle is having to manually append a wildcard to the query term, perhaps this should be an option, e.g.
wildcardwith the valuestrailing | leading | wrapped | none, I’ll have a think about it.You could express this within a query string and the
searchmethod like this if you want to try things out: