fast-trie-search
Advanced tools
Comparing version 1.1.5 to 1.2.0
@@ -23,2 +23,3 @@ "use strict"; | ||
addKey: false, | ||
searchStartIndex: 0, | ||
excludeNodes: ["and", "the", "of", "with", "without", "in", "on", "&", "at", "as", "or", "type"] | ||
@@ -58,3 +59,3 @@ }; | ||
for (let i = 0; i < expandedObjArray.length; i++) { | ||
add(expandedObjArray[i], 0, root); | ||
add(expandedObjArray[i], 0, root, opts.searchStartIndex); | ||
} | ||
@@ -66,5 +67,12 @@ // empty out the top level array as it serves no purpose and adds to the size | ||
exports.generateTrie = generateTrie; | ||
const add = (str, startIndex, root) => { | ||
// searchStartIndex : the number of letters to type at which the search will return results. THis is | ||
// helpful in use cases where its unecessary to start at the first letter and helps reduce the trie size | ||
const add = (str, startIndex, root, searchStartIndex) => { | ||
// console.log("STR: ", str) | ||
// console.log("str.nd: ", str.nd) | ||
// console.log("startIndex: ", startIndex) | ||
// console.log("-------------------------------------") | ||
let node = str.node; | ||
if (startIndex === node.length) { | ||
root["w"] = []; | ||
root.w.push(str); | ||
@@ -76,4 +84,10 @@ return; | ||
} | ||
root.w.push(str); | ||
add(str, startIndex + 1, root.m[node[startIndex]]); | ||
if (startIndex >= searchStartIndex) { | ||
root["w"] = []; | ||
root.w.push(str); | ||
} | ||
else { | ||
delete root.w; | ||
} | ||
add(str, startIndex + 1, root.m[node[startIndex]], searchStartIndex); | ||
}; | ||
@@ -80,0 +94,0 @@ const search = (str, startIndex, root) => { |
@@ -5,2 +5,3 @@ type Options = { | ||
splitRegex?: string; | ||
searchStartIndex?: number; | ||
excludeNodes?: string[]; | ||
@@ -7,0 +8,0 @@ }; |
@@ -18,2 +18,3 @@ import parseRegex from "regex-parser"; | ||
addKey: false, | ||
searchStartIndex: 0, | ||
excludeNodes: ["and", "the", "of", "with", "without", "in", "on", "&", "at", "as", "or", "type"] | ||
@@ -53,3 +54,3 @@ }; | ||
for (let i = 0; i < expandedObjArray.length; i++) { | ||
add(expandedObjArray[i], 0, root); | ||
add(expandedObjArray[i], 0, root, opts.searchStartIndex); | ||
} | ||
@@ -60,5 +61,12 @@ // empty out the top level array as it serves no purpose and adds to the size | ||
}; | ||
const add = (str, startIndex, root) => { | ||
// searchStartIndex : the number of letters to type at which the search will return results. THis is | ||
// helpful in use cases where its unecessary to start at the first letter and helps reduce the trie size | ||
const add = (str, startIndex, root, searchStartIndex) => { | ||
// console.log("STR: ", str) | ||
// console.log("str.nd: ", str.nd) | ||
// console.log("startIndex: ", startIndex) | ||
// console.log("-------------------------------------") | ||
let node = str.node; | ||
if (startIndex === node.length) { | ||
root["w"] = []; | ||
root.w.push(str); | ||
@@ -70,4 +78,10 @@ return; | ||
} | ||
root.w.push(str); | ||
add(str, startIndex + 1, root.m[node[startIndex]]); | ||
if (startIndex >= searchStartIndex) { | ||
root["w"] = []; | ||
root.w.push(str); | ||
} | ||
else { | ||
delete root.w; | ||
} | ||
add(str, startIndex + 1, root.m[node[startIndex]], searchStartIndex); | ||
}; | ||
@@ -74,0 +88,0 @@ const search = (str, startIndex, root) => { |
@@ -5,2 +5,3 @@ type Options = { | ||
splitRegex?: string; | ||
searchStartIndex?: number; | ||
excludeNodes?: string[]; | ||
@@ -7,0 +8,0 @@ }; |
{ | ||
"name": "fast-trie-search", | ||
"version": "1.1.5", | ||
"version": "1.2.0", | ||
"description": "This package can be used to implement a Search-As-You-Type funtionality and uses a Trie data structure ", | ||
@@ -5,0 +5,0 @@ "exports": { |
@@ -35,4 +35,9 @@ ![](https://nodei.co/npm/fast-trie-search.png?downloads=True&stars=True) | ||
return the data that you need | ||
addKey : Some use cases, say if you're ouputting a list on a React app, require a unique key for each item on the list | ||
DEFAULT: false | ||
searchStartIndex : the number of letters to type at which the search will return results. This is | ||
helpful in use cases where its unecessary to start at the first letter and helps reduce the trie size | ||
splitRegex : This is the character on which to split the searchProp input. For eg, if the value of the input property, "name" | ||
@@ -39,0 +44,0 @@ is "Oven-fried pork chops" and we want to be able to type "pork" or "chops" or "oven" to get this result back, then |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
19974
232
154