Class TrieSearch<T>
Type Parameters
- T extends object
Constructors
constructor
- new TrieSearch<T extends object>(
 keyFields?: string | KeyFields,
 options?: TrieSearchOptions,
 ): TrieSearch<T>Type Parameters- T extends object
 Parameters- OptionalkeyFields: string | KeyFields- A 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. 
- Optionaloptions: TrieSearchOptions- Options. 
 Returns TrieSearch<T>
Accessors
isDestroyed 
- get isDestroyed(): booleanReturns booleanWhether this TrieSearch instance has been destroyed. 
keyFields 
- Returns KeyFields- A clone of the current key fields. 
root
size
- get size(): numberReturns numberNumber of nodes in the trie data structure. 
Methods
add
clear
- Clears all items. - Returns this- This instance. 
destroy
- Destroys this TrieSearch instance. Removing all data and preventing new data from being added. Any subscribers are notified with an undefined argument in the callback signaling that the associated instance is destroyed. - Returns this
map
- Directly maps an item to the given key. - Parameters- key: stringThe key to store the item. 
- value: TThe item to store. 
 - Returns this
- key: string
search
- search(
 phrases: string | Iterable<string, any, any>,
 options?: { limit?: number; list?: T[]; reducer?: TrieSearchReducer<T> },
 ): 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 ORlookup. You may provide areducerfunction to change the behaviorParameters- phrases: string | Iterable<string, any, any>The phrases to parse and search in the trie data structure. 
- Optionaloptions: { limit?: number; list?: T[]; reducer?: TrieSearchReducer<T> }- Search Options. - Optionallimit?: number- The limit for search results returned. 
- Optionallist?: T[]- An external array to use for storing search results. 
- Optionalreducer?: TrieSearchReducer<T>- A trie reducer instance to apply to this search. 
 
 Returns T[]Found matches. 
- phrases: string | Iterable<string, any, any>
subscribe
- 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. 
- 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
splitOnRegExoption.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
expandRegexesobject.