Skip to content

SearchResult

A single fuzzy search result with the matched item and its score.

Property Type Description
index number The index of the item in the original input array.
item string The matched item. Strings are converted to UTF-8 on the way into Rust, so this is the same string as items[index] unless that one contains a lone UTF-16 surrogate (for example from slicing an emoji in half), which becomes U+FFFD; index always identifies your string.
matchType? MatchType How the query matched this item (Exact, Prefix, Contains, or Fuzzy). Only present when includePositions is set to true in SearchOptions. Derived from positions at zero additional cost.
positions number[] Indices of the matched characters of the item, in ascending order. An ASCII item is counted by character; any other item by grapheme cluster (a user-perceived character, such as an emoji with its modifiers or a letter with its combining marks), so these are not UTF-16 string offsets. highlight() and highlightRanges() convert them. Empty unless includePositions is set to true in SearchOptions.
score number The match score normalized to 0.0-1.0 range (1.0 is a perfect match).