npm install node-levenshtein-automata
When requiring the module a simple Factory Function will be returned allowing you to create a basic memory store and an index which will be used for loading text and searching. When creating the index there are several possible arguments that could be passed into the constructor.
var lev =memStore = levidx = lev;
Creating a memory store as shown above will keep all indexes together in the same object. This requires that all index names (first argument to createIndex) are unique. If that is not desireable, simply omitting the "store" argument to createIndex will create a separate memory store per index.
Note: this is only applicable to MemoryStore
var idx = lev;
Redis may be used as the backing store for indexing and searching. Using RedisStore is simple:
var lev =store = lev //args are redis specific argumentsidx = lev;
Text input may be in the form of a string or array of strings. The second argument is an id. It can be integer or string.
var doc ="some string to index""I love surfing videos on @youtube"" is pretty cool too"idxindexdoc 111;idxindex'this is another test string' "222333";
Search can be done by simply passing in the query term and optionally passing in the max edit distance for the particular query. Otherwise the default provided in the constructor will be used. Lastly a callback must be provided which will receive error and data arguments. The data parameter may be an emptry array if no match was found or an array containing the id, one or more arrays with the term and its levenshtein distance, total count of matches, and the initial query term.
For more information about the details behind Levenshtein Automata and how this module implements it visit dylon's Levenshtein Automata Github page.