EthanRutherford / fast-fuzzy

Fast fuzzy search utility
ISC License
376 stars 8 forks source link

Fuzzy search in any order #27

Closed dwyzlic-ias closed 1 year ago

dwyzlic-ias commented 1 year ago

Hi!

Today if I have:

const searcher = new Searcher(["hello world"]);
searcher.search("world hello"); //returns []

The algorithm doesn't work when words are not in the good order, is there any way to fix that?

EthanRutherford commented 1 year ago

If you want something like this, I would suggest tokenizing the inputs. Fast fuzzy is a lower-level library that excels at matching individual words, the original use case for this library was for use in autocomplete/autocorrect systems. However, it is possible to extend this functionality into something higher level, like this example (or for searching across entire documents).

One can use the keySelector option to take the search term "hello world" and return an array of tokens ["hello", "world"]. This will make the value match on either word. Then you can further divide the search term "world hello" into ["world", "hello"], run a search on each token, and combine the results to determine best match.

leeoniya commented 1 year ago

shameless plug for a lib that does this out-of-order matching quite well ;)

https://github.com/leeoniya/uFuzzy