@sirbob01/fuzzyjs

A lightweight fuzzy search algorithm

Usage no npm install needed!

<script type="module">
  import sirbob01Fuzzyjs from 'https://cdn.skypack.dev/@sirbob01/fuzzyjs';
</script>

README

FuzzyJS

A lightweight fuzzy search implementation for JavaScript. It uses the Overlap coefficient for an intersection test, the Damerau–Levenshtein algorithm to measure the edit distance between token pairs, and an n-gram hashtable to probabilistically determine the total weighted similarity score.

Dependencies

None. Pure JavaScript.

Basic Usage

  1. Create a new Fuzzy() object.
var fuzzy = new Fuzzy();
  1. 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?
};
  1. Index the search space into the Fuzzy engine.
var keys = ["Hello", "Helper", "world", "bob"];
fuzzy.index(keys);
  1. Search for a query and get an array of matches.
var results = fuzzy.search("hell"); // ["Hello", "Helper"]