VDL Plugin SDK

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:

  1. Exact normalized match
  2. Prefix match
  3. Suffix match
  4. Contains match
  5. Edit-distance match

The edit-distance threshold adapts to the normalized query length:

  • <= 4 code points: 1
  • <= 8 code points: 2
  • > 8 code 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

ParameterTypeDescription
datareadonly string[]Candidate words to search.
querystringSearch query.

Returns

FuzzySearchResult

The best matches plus the literal exact-match flag.

Example

fuzzySearch(["User", "UserService", "SuperUser"], "user")
// {
//   matches: ["User", "UserService", "SuperUser"],
//   exactMatchFound: false,
// }