diff --git a/dist/wade.js b/dist/wade.js index 519768a..5c96349 100644 --- a/dist/wade.js +++ b/dist/wade.js @@ -67,6 +67,20 @@ return match; } + var addMultiplePatternTrie = function(parent, id, item) { + var node = parent; + for(var i = item.length - 1; i > 0; i--) { + var newNode = node[item[i]]; + newNode = newNode === undefined ? {} : newNode; + node[item[i]] = newNode; + node = newNode; + } + + node[item[0]] = { + id: id + } + } + var lowercase = function(str) { return str.toLowerCase(); } @@ -120,7 +134,10 @@ } } } else { - + var trie = {}; + for(var i = 0; i < keywordsLength; i++) { + addMultiplePatternTrie(trie, i, keywords[i]); + } } return results; diff --git a/dist/wade.min.js b/dist/wade.min.js index 04f4594..93cc134 100644 --- a/dist/wade.min.js +++ b/dist/wade.min.js @@ -3,4 +3,4 @@ * Copyright 2017 Kabir Shah * Released under the MIT License */ -!function(e,r){"object"==typeof module&&module.exports?module.exports=r():e.Wade=r()}(this,function(){var e=function(e,r){for(var t=!1,o=0;o=0;h--){var s=e[h],u=o[h+n];if(s!==u){var f=t[u];n+=void 0===f?h+1:f,i=!1;break}i=!0}if(!0===i)break}return i},o=function(e){return e.toLowerCase()},n=["about","after","all","also","am","an","and","another","any","are","as","at","be","because","been","before","being","between","both","but","by","came","can","come","could","did","do","each","for","from","get","got","has","had","he","have","her","here","him","himself","his","how","if","in","into","is","it","like","make","many","me","might","more","most","much","must","my","never","now","of","on","only","or","other","our","out","over","said","same","see","should","since","some","still","such","take","than","that","the","their","them","then","there","these","they","this","those","through","to","too","under","up","very","was","way","we","well","were","what","where","which","while","who","with","would","you","your","a","i"],a=function(e){for(var r=e.split(" "),t=0;t=0;h--){var s=e[h],u=t[h+n];if(s!==u){var f=o[u];n+=void 0===f?h+1:f,i=!1;break}i=!0}if(!0===i)break}return i},t=function(e,r,o){for(var t=e,n=o.length-1;n>0;n--){var a=t[o[n]];a=void 0===a?{}:a,t[o[n]]=a,t=a}t[o[0]]={id:r}},n=function(e){return e.toLowerCase()},a=["about","after","all","also","am","an","and","another","any","are","as","at","be","because","been","before","being","between","both","but","by","came","can","come","could","did","do","each","for","from","get","got","has","had","he","have","her","here","him","himself","his","how","if","in","into","is","it","like","make","many","me","might","more","most","much","must","my","never","now","of","on","only","or","other","our","out","over","said","same","see","should","since","some","still","such","take","than","that","the","their","them","then","there","these","they","this","those","through","to","too","under","up","very","was","way","we","well","were","what","where","which","while","who","with","would","you","your","a","i"],i=function(e){for(var r=e.split(" "),o=0;o 0; i--) { + var newNode = node[item[i]]; + newNode = newNode === undefined ? {} : newNode; + node[item[i]] = newNode; + node = newNode; + } + + node[item[0]] = { + id: id + } +} + var lowercase = function(str) { return str.toLowerCase(); } @@ -110,7 +124,10 @@ var Wade = function(data) { } } } else { - + var trie = {}; + for(var i = 0; i < keywordsLength; i++) { + addMultiplePatternTrie(trie, i, keywords[i]); + } } return results;