Skip to content

Build your personal knowledge base with Trilium Notes

simple custom tokenizer search instead of fuse

azivner9e5fcb8be262
diff --git a/static/js/init.js b/static/js/init.js
index d7f33020cc..9b989ab45c 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