kentcdodds / match-sorter

Simple, expected, and deterministic best-match sorting of an array in JavaScript
https://npm.im/match-sorter
MIT License
3.73k stars 129 forks source link

Result limiting with early exit #69

Closed KeKs0r closed 5 years ago

KeKs0r commented 5 years ago

Hi,

I am trying to have a local version of a search, which uses a big list of preloaded results (1200 items).

When the user starts typing, the result set for 1-3 letters is very long. I would still like to fastly return a response of e.g. 5 items. With my current data this filtering takes already 50-90ms.

I know the question was already raised here: https://github.com/kentcdodds/match-sorter/issues/52

But the proposed solution does not help the performance hit. Would it be possible to define a number of items that should be matched with certain threshold and then let the match sort return early?

kentcdodds commented 5 years ago

Hi @KeKs0r,

The tricky thing here is how does match-sorter know when it has the 5 best matches without going through all the items?

If you really have a huge list of items, then it's better to have the sorting happen on a server and for the server to only return the best matches.

Unfortunately, there's nothing that we can do here. Good luck.

KeKs0r commented 5 years ago

Just in case some people will find this. I ended up using this package: https://www.npmjs.com/package/trie-search to have performant lookups. Be aware that it works very differently than match sorter.