Fuzzy Search
Performs a fuzzy search by matching characters in sequence against array elements.
fuzzySearch()
Performs a fuzzy search by matching characters in sequence against array elements.
Important Note
- You should not use this method explicitly unless you have a specific use case that requires it.
- Instead, consider using the
{ fuzzy: true }option in thefindOne,findAll,findOneAsync, andfindAllAsyncmethods to enable fuzzy search.
Signature
fuzzySearch(
array: T[],
matcher: string,
keySelector: (item: T) => string | number,
caseInsensitive: boolean
): T | undefinedParameters
| Parameter | Type | Description |
|---|---|---|
array | T[] | The collection to search. |
matcher | string | The sequence to search for (e.g. 'cmn' matches 'California'). |
keySelector | (item: T) => string | number | Value extractor function. |
caseInsensitive | boolean | Whether to ignore character case. |
Description
The fuzzySearch method implements a flexible pattern matching algorithm that:
- Finds items where the search characters appear in order (but not necessarily consecutively).
- Supports both string and numeric property values.
- Provides case sensitivity control.
- Returns the first matching item found.
Example Usage
playground.ts
Performance Characteristics
- Time Complexity:
O(n)wherenis array length. - Best For: Small to medium datasets (less than 1000 items).
- Cache Note: Results are not cached automatically.
Use Cases
- Implementing type-ahead search suggestions.
- Finding approximate matches in user-generated content.
- Handling potential typos in search queries.
- Creating flexible filtering interfaces.
Last updated: Sun, Jul 19, 2026 09:00:11AM (UTC)
