Class TrieSearch<T>
Type Parameters
Constructors
constructor
- new
Trie <T>(keyFields?, options?): TrieSearch<T>Search Type Parameters
Parameters
Optional
keyFields: string | KeyFieldsA single string or an array of strings / arrays representing what fields on added objects are to be used as keys for the trie search / HashArray.
Optional
options: TrieSearchOptionsOptions.
Returns TrieSearch<T>
Accessors
isDestroyed
- get isDestroyed(): boolean
Returns boolean
Whether this TrieSearch instance has been destroyed.
keyFields
root
size
- get size(): number
Returns number
Number of nodes in the trie data structure.
Methods
add
clear
destroy
map
- map(key, value): this
Directly maps an item to the given key.
Parameters
- key: string
The key to store the item.
- value: T
The item to store.
Returns this
- key: string
search
- search(phrases, options?): T[]
Performs a search of the trie data structure with the given phrases. By default, each phrase is split by TrieSearchOptions.splitOnGetRegEx and matches found for each word resulting in a
OR
lookup. You may provide areducer
function to change the behaviorParameters
- phrases: string | Iterable<string, any, any>
The phrases to parse and search in the trie data structure.
Optional
options: {
limit?: number;
list?: T[];
reducer?: TrieSearchReducer<T>;
}Search Options.
Optional
limit?: numberThe limit for search results returned.
Optional
list?: T[]An external array to use for storing search results.
Optional
reducer?: TrieSearchReducer<T>A trie reducer instance to apply to this search.
Returns T[]
Found matches.
- phrases: string | Iterable<string, any, any>
subscribe
- subscribe(handler): (() => void)
Subscribe for change notification on add / clear / destroy.
Note: There is no data defined regarding what changed only that one of three actions occurred. This TrieSearch instance is sent as the only argument. When it is undefined this signals that the TrieSearch instance has been destroyed.
Parameters
- handler: TrieSearchSubscribeHandler<T>
Callback function that is invoked on changes (add / clear / destroy).
Returns (() => void)
Unsubscribe function.
- (): void
Returns void
- handler: TrieSearchSubscribeHandler<T>
A Trie is a data structure designed for quick reTRIEval of objects by string search. This was designed for use with a type-ahead search (e.g. like a dropdown) but could be used in a variety of situations.
This data structure indexes sentences / words to objects for searching by full or partial matches. So you can map 'hello' to an Object, and then search by 'hel', 'hell', or 'hello' and get the Object or an Array of all objects that match.
By default, sentences / words are split along whitespace boundaries. For example, if your inserted mapping is 'the quick brown fox', this object will be searchable by 'the', 'quick', 'brown', or 'fox' or any of their partials like 'qui' or 'qu' or 'fo'. Boundaries can be customized using the
splitOnRegEx
option.By default, the trie-search is internationalized for a common set of vowels in the ASCII set. So if you insert 'รถ', then searching on 'o' will return that result. You can customize this by providing your own
expandRegexes
object.