SearchRule
Select strings from your items to search against
A Finder instance has a single searchTerm string that will be compared against haystacks extracted from the items array.
Use a searchFn to extract the string/strings from each item that will be compared against the searchTerm needle.
Type Signature
const rule = searchRule<FItem, FContext>({
id?: string
searchFn: (item: FItem, context: FContext) => string | string[];
debounceMilliseconds?: number;
})
Only a single search rule can be defined per Finder instance. If you need to do multiple kinds of text searches, consider using a Filter!
Search algorithm
Finder uses case-insensitive sequential character matches.
- Searching for "pru" in "hydraulic pressure" matches "hydraulic pressure"
- Searching for "dyr" in "hydraulic pressure" does not match.
- Searching for "r a s s e" in "hydraulic pressure" matches "hydraulic pressure".
Sorted results
Finder sorts results to find the closest matches. A search score is summed based on:
Ratio of matched characters to haystack length. ( Scored 0-100 )
With the needle ap, app has a score of 66, while apple is 40.
Comparative length of sequential character matches. ( Scored 0-100 )
With the needle orange, orc angel has a score of 80, while delicious oranges is 100.
Both scores are equally weighted.
Ranked search will be overridden if a sortBy rule is set. If you want to use both ranked search and sortBy rules, you'll need to enable ignoreSortByRulesWhileSearchRuleIsActive in your configuration object.
Custom search algorithms
If this search algorithm or sorting doesn't meet your needs, you may want to create a filter or a custom sortBy rule.