fast-trie-search
Advanced tools
Comparing version 1.1.2 to 1.1.3
{ | ||
"name": "fast-trie-search", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "This package can be used to implement a Search-As-You-Type funtionality and uses a Trie data structure", | ||
@@ -32,3 +32,3 @@ "exports": { | ||
"type": "git", | ||
"url": "fast-trie-search" | ||
"url": "fhttps://github.com/lalitisbhatia/fast-trie-search" | ||
}, | ||
@@ -35,0 +35,0 @@ "keywords": [ |
@@ -5,3 +5,3 @@ ![](https://nodei.co/npm/fast-trie-search.png?downloads=True&stars=True) | ||
The package contains 2 exposed methods and types. | ||
The package contains 2 exposed methods and 2 types. | ||
#### generateTrie() | ||
@@ -22,5 +22,5 @@ This generates a Trie object out of the input data source | ||
``` | ||
# Basic Usage | ||
## GENERATING THE TRIE OBJECT | ||
generateTrie(args) | ||
## Basic Usage (TypeScript) | ||
### GENERATE THE TRIE | ||
generateTrie(args) | ||
@@ -33,3 +33,3 @@ ARGS: | ||
options (optional params): | ||
outputProps : Upon search each returned item is an object and we dont have to return the entire object from the | ||
outputProps : Upon search, each returned item is an object and we dont have to return the entire object from the | ||
from each object in objArray - only return what is needed for your specific use case | ||
@@ -41,6 +41,6 @@ DEFAULT: return the entire object - Be careful as the returned Trie is a large object so only | ||
splitRegex : This is the character on which to split the searchProp input. For eg, if the value of the input property, "name" | ||
is "Oven-fried pork chops" and we want to be able to type pork or chops or oven to get this result back, then | ||
is "Oven-fried pork chops" and we want to be able to type "pork" or "chops" or "oven" to get this result back, then | ||
the input regex can be just "/[ ]/" ( just a space). | ||
BUT, if u want this result to come back for typing "fried" as well, | ||
then the splitRegex should include the "-" charactr as well, so the input value of splitRegex will be "/[ -]/" | ||
then the splitRegex should include the "-" charactr , so the input value of splitRegex will be "/[ -]/" | ||
DEFAULT: " " ( space character) | ||
@@ -72,3 +72,3 @@ | ||
Sti.., fried, chi.. , broccoli, red, pepp... , cashe... etc | ||
3. In the search result, only the properties "name","id","ingredients" should be returned ( since the use case doesnt need other propoerties | ||
3. In the search result, only the properties "name","id","ingredients" should be returned ( since the use case doesnt need other properties | ||
and by specifying the specific properties, we save on the size of the Trie object) | ||
@@ -80,3 +80,3 @@ 4. Show as a list on a React app so each item needs a unique key identifier | ||
## Basic Usage (TypeScript) | ||
``` | ||
@@ -93,3 +93,3 @@ import {search,generateTrie,Options, TrieNode} from "fast-trie-search" | ||
splitRegex : "/[ -]/", | ||
excludeNodes : ['the','a','for','with','of'] | ||
excludeNodes : ['the','a','for','with','of','cooked','raw','solid','liquid'] | ||
} | ||
@@ -100,18 +100,24 @@ const root:TrieNode generateTrie(recipesArray,searchProp,options) | ||
### Notes | ||
#### Notes | ||
- This could be used in a backend service to return a Trie object on an api that a client can then use to search | ||
- WARNING: The Trie object can become pretty large for large data sets - we're sacrificing space for speed so make sure that the Trie object is generated only once and then cached if doesnt change too often, | ||
- WARNING: The Trie object can become pretty large for large | ||
data sets - we're sacrificing space for speed so make sure | ||
that the Trie object is generated only once and then cached if | ||
doesnt change too often, | ||
## USING THE TRIE OBJECT TO SEARCH | ||
### SEARCH THE TRIE | ||
search(searchString, index, root) // default i=0, root is the full trie object | ||
If the Trie object is returned by an external service, then the client side will also need to import this package | ||
and in the onChange handler of the search input field, call the search method as shown in a React example below that is using | ||
useState for 2 properties: searchTerm and searchResults and using the corresponding setSearchResults method to update the component | ||
with the search results | ||
If the Trie object is returned by an external service, then | ||
the client side will also need to import this package and | ||
in the onChange handler of the search input field, call the | ||
search method as shown in a React example below that is | ||
using useState for 2 properties: searchTerm and | ||
searchResults and using the corresponding setSearchResults | ||
method to update the component with the search results | ||
## Client Side Usage (React Example) | ||
#### Client Side Usage (React Example) | ||
``` | ||
import {search} from "fast-trie-search" | ||
import {search} from "fast-trie-search" | ||
.... | ||
@@ -118,0 +124,0 @@ () => { |
18429
149