1.0.2 • Published 3 years ago
@sirbob01/fuzzyjs v1.0.2
FuzzyJS
This library is a lightweight fuzzy search implementation for JavaScript. It uses the following metrics to determine the similarity of two strings:
- Measure the edit distance between token pairs with the Damerau–Levenshtein algorithm
- Test token set intersections using the overlap coefficient formula
- N-gram hash table
All three metrics are used to produce a weighted similarity score.
Dependencies
None, just vanilla JavaScript.
Basic Usage
- Create a new
Fuzzy()
object.
var fuzzy = new Fuzzy();
- Set the parameters for the search. The scores calculated by the engine range from 0 (completely different) to 1.0 (exact match).
fuzzy.options = {
sort : true, // Sort results by final score
n_size : 3, // N-gram size
min_query : 2, // Minimum query length
score_threshold : 0.4, // Minimum total similarity score
edit_threshold : 0.6, // Minimum edit score
all_matches : true // Return all potential matches?
};
- Index the search space into the Fuzzy engine.
var keys = ["Hello", "Helper", "world", "bob"];
fuzzy.index(keys);
- Search for a query and get an array of matches.
var results = fuzzy.search("hell"); // ["Hello", "Helper"]
License
Code and documentation Copyright (c) 2019-2020 Keith Leonardo
Code released under the BSD 3 License.