fuzzyset.js Fork

2012/12/27

fuzzyset.js is a data structure that performs something akin to fulltext search against data to determine likely mispellings and approximate string matching. It works like this:

a = FuzzySet(['Glen', 'Chiacchieri']);
a.get("glenn");
[[0.8, 'Glen']]
a.get('chiachcieri');
[[0.8181818181818181, 'Chiacchieri']]

It uses cosine similarity and Levenshtein distance to return a list of likely results from the set with a match score from 0 to 1.

fuzzyset.js is a JavaScript (and node.js) port of a python library called fuzzyset. I ported it to JavaScript because I liked its functionality and wanted to learn more about its underlying algorithms by recoding it. I also wanted the same functionality in JavaScript so I could use it for misspellings when searching in Select2 dropdowns (among other things). Due to its simplicity, the port was not that hard and runs quite well.