How fast-fuzzy works: Methodology and Ranking
masterfast-fuzzy uses a modified Levenshtein distance algorithm (specifically the Sellers substring match) and uses Damerau-Levenshtein distance by default to handle transpositions more gracefully.
Key Concepts
- Normalization: Inputs are normalized via UTF-8 normalization, optional lowercasing, optional symbol stripping, and optional whitespace flattening/trimming. Graphemes (like conjoined emojis) are treated as single characters.
- Scoring: Results are scored from
0to1. - Tie-breaking:
- Ties in score are broken by the earliness of the match (when using Sellers).
- Further ties are broken by favoring candidates whose length is closest to the search term length (favoring exact matches).
- Final ties are broken by insertion order.
- Performance: Candidates are stored in a trie. This allows the algorithm to skip entire subtrees if they cannot possibly meet the
thresholdscore, making it much faster than brute-force search.