Gathering detailed insights and metrics for node-levenshtein-automata
Gathering detailed insights and metrics for node-levenshtein-automata
Gathering detailed insights and metrics for node-levenshtein-automata
Gathering detailed insights and metrics for node-levenshtein-automata
npm install node-levenshtein-automata
Typescript
Module System
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
#node-levenshtein-automata ##Levenshtein Automata module for Nodejs based on Dylon Edwards great implementation
Based on the dylon implementation of Levenshtein Automata, a nodejs module wrapper that attempts to simplify the use of this algorithm for automating fuzzy text search.
Installation:
1npm install node-levenshtein-automata
###Instantiating the module: 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.
1var lev = require('node-levenshtein-automata') 2 , memStore = lev.MemoryStore() 3 , idx = lev.createIndex('twits', {store: memStore});
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
1var idx = lev.createIndex('twits');
###Redis Store Redis may be used as the backing store for indexing and searching. Using RedisStore is simple:
1var lev = require('node-levenshtein-automata') 2 , RedisStore = lev.RedisStore() 3 , store = new RedisStore(args) //args are redis specific arguments 4 , idx = lev.createIndex('twits', {store: store});
###Indexing 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.
1 2var doc = [ 3 "some string to index", 4 "I love surfing videos on @youtube", 5 "https://github.com/rhasson is pretty cool too" 6] 7 8idx.index(doc, 111); 9idx.index('this is another test string', "222333");
###Searching 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.
1idx.search('youtube', 2, function(err, data) { 2 console.log(data) // {id: 111, terms: [ ['youtube', 0] ], count: 1, query: 'youtube'} 3}); 4 5idx.search('youtube videos', onResponse);
For more information about the details behind Levenshtein Automata and how this module implements it visit dylon's Levenshtein Automata Github page.
No vulnerabilities found.
No security vulnerabilities found.