fuzzySearch
Import from @varavel/vdl-plugin-sdk/utils/strings.
function fuzzySearch(data, query): FuzzySearchResult;
Performs a fuzzy search that combines structural matching with a bounded Damerau-Levenshtein distance.
Ranking priority, from best to worst:
- Exact normalized match
- Prefix match
- Suffix match
- Contains match
- Edit-distance match
The edit-distance threshold adapts to the normalized query length:
<= 4code points:1<= 8code points:2> 8code points:3
The implementation is optimized for interactive lookups:
- normalization work is cached per distinct input word
- structural matches short-circuit before edit-distance work
- edit-distance evaluation is banded and threshold-aware
- only the best three matches are retained during the scan
Parameters
| Parameter | Type | Description |
|---|---|---|
data | readonly string[] | Candidate words to search. |
query | string | Search query. |
Returns
The best matches plus the literal exact-match flag.
Example
fuzzySearch(["User", "UserService", "SuperUser"], "user")
// {
// matches: ["User", "UserService", "SuperUser"],
// exactMatchFound: false,
// }