From 9e5fcb8be2628f0fd963e1afa038b1c5d01e4f80 Mon Sep 17 00:00:00 2001 From: azivner Date: Mon, 18 Sep 2017 20:07:56 -0400 Subject: [PATCH] simple custom tokenizer search instead of fuse --- static/js/init.js | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/static/js/init.js b/static/js/init.js index d7f33020c..9b989ab45 100644 --- a/static/js/init.js +++ b/static/js/init.js @@ -63,6 +63,45 @@ $.ui.autocomplete.filter = function (array, terms) { ] }; + + const startDate = new Date(); + const fuse = new Fuse(array, options); // "list" is the item array - return fuse.search(terms); + + const results = fuse.search(terms); + + console.log("Search took " + (new Date().getTime() - startDate.getTime()) + "ms"); + + return results; +}; + +$.ui.autocomplete.filter = function (array, terms) { + if (!terms) { + return []; + } + + const startDate = new Date(); + + const results = []; + const tokens = terms.toLowerCase().split(" "); + + for (const item of array) { + let found = true; + const lcValue = item.value.toLowerCase(); + + for (const token of tokens) { + if (lcValue.indexOf(token) === -1) { + found = false; + break; + } + } + + if (found) { + results.push(item); + } + } + + console.log("Search took " + (new Date().getTime() - startDate.getTime()) + "ms"); + + return results; }; \ No newline at end of file