Open Benjamin-Dobell opened 6 years ago
Wildcard matching an empty string seems entirely reasonable. The current behaviour is more likely an omission rather than a deliberate choice.
I need to investigate another bug in the code that handles wildcard so I'll take a look at fixing this also.
Hmm, this might not be a problem with lunr.TokenSet
since there is a test specifically for matching zero or more characters.
Oh gosh this has been an issue since 2019 gasp Bitwarden uses this library, and it's not possible to search for empty usernames on the Bitwarden database. Is there no timeline for fixing? No alternative to search for empty string in a field? Thanks.
Wildcard presently does not match an empty (zero length) string, where as it's reasonable to expect that it does.
e.g.
Searching for
blue*
will not match an indexed document with the text "The sky is blue". However, searching forblue
, will correctly return a match.This is problematic as it typically necessitates two queries where one ought to suffice e.g.
This also leads to the overhead of having a separate
Set
to remove duplicate match results.The problem is somewhat exacerbated by the lack of sub-query support (mentioned in the last comment in https://github.com/olivernn/lunr.js/issues/264). If we had sub-queries (OR/ADD) then the existing wildcard behaviour would be passable as we could just do something like:
As it stands, you instead need to perform an entirely separate query, with just the last search term altered, in order to correctly match user input as it's typed.