/** * A trie data structure optimized for approximate string matching, * allowing for flexible yet controlled searches based on lexicographical * distance. * * This class provides methods to add items with associated search strings and * to perform searches within a specified maximum Levenshtein distance. * * Levenshtein distance is a metric used in computer science and information * theory to measure the difference between two sequences of characters. * It's also known as the edit distance. * * Specifically, the Levenshtein distance between two words is the minimum * number of single-character edits (insertions, deletions, or substitutions) * required to change one word into the other. * * For example: * * The Levenshtein distance between "kitten" and "sitting" is 3: * * kitten → sitten (substitution of "s" for "k") * sitten → sittin (substitution of "i" for "e") * sittin → sitting (insertion of "g" at the end) * The Levenshtein distance between "book" and "back" is 2: * * book → bock (substitution of "c" for "o") * bock → back (substitution of "a" for "o") * * Using Levenshtein distance in this class allows the search to return * results that are close matches to the search term, even if they're * not exact matches. The results are then sorted based on this distance, * with the closest matches (lowest Levenshtein distance) appearing first * in the results array. * * This approach is particularly useful for implementing features like * autocorrect, spell-checking, or fuzzy search functionality where you * want to find close matches to a given input string. * * ------------------------------------------------------------------------ * * Usage: * 1. Create an instance of FuzzyTrie: * const trie = new FuzzyTrie(); * * 2. Add items to the trie: * trie.addItemToTrie("search string", yourItem); * You can add multiple items with the same or different search strings. * * 3. Perform a fuzzy search: * const results = trie.searchItems("query string", maxAllowedDistance); * - "query string" is the search term * - maxAllowedDistance is the maximum Levenshtein distance allowed (default is 2) * * 4. The search returns an array of items sorted by their Levenshtein distance * from the query string, with the closest matches first. * * Example: * const trie = new FuzzyTrie(); * trie.addItemToTrie("apple", "Apple fruit"); * trie.addItemToTrie("banana", "Banana fruit"); * const results = trie.searchItems("aple", 1); * // results will contain ["Apple fruit"] */ declare class FuzzyTrie { private rootNode; private calculateLevenshteinDistance; addItemToTrie(searchString: string, itemToAdd: T): void; searchItems(queryString: string, maxAllowedDistance?: number): T[]; } export { FuzzyTrie };