fast-matcher
Most autocomplete implementations I've seen do full-list scanning and simple (infix) text matching.
The standard performance optimizations seem to be complex: indexing, caching, tries, etc.
This library is a simpler and much faster "back end" for autocompletes. It isn't as
full-featured, which means it can make some assumptions for really big perf wins, namely:
- It only does prefix matching.
In my experience this actually makes perfect sense in a lot of cases. For example suppose your user
is searching for a company name; they aren't going to type "o" or "e" to search for Home Depot. Or
say they're using a dictionary; they aren't going to type "n" to search for anagram.
See for yourself how fast this is in practice: the demo uses
this library to provide autocomplete results from WordNet, with
close to 150,000 words. Results are pretty much instantaneous.
Usage
var matcher = new FastMatcher(list, options);
var matches = matcher.getMatches(prefix);
var list = [
{ x: 'foo' },
{ x: 'bar' },
{ x: 'baz' }
];
var matcher = new FastMatcher(list, {
selector: 'x',
caseInsensitive: true,
limit: 25
});
matcher.getMatches('ba');
Has this been done before?
Probably. I don't know.