From c255d148d84ddc305fdd2b7e6a119ff1a89ddffb Mon Sep 17 00:00:00 2001
From: Aditya Telange <21258296+adityatelange@users.noreply.github.com>
Date: Sat, 10 Apr 2021 00:58:40 +0530
Subject: [PATCH] Fix results being searched before index building; refactor
resultSet generation to fix duplicate items with large db
---
assets/js/fastsearch.js | 35 ++++++++++++++++-------------------
1 file changed, 16 insertions(+), 19 deletions(-)
diff --git a/assets/js/fastsearch.js b/assets/js/fastsearch.js
index 4b9fdb64..4e10778b 100644
--- a/assets/js/fastsearch.js
+++ b/assets/js/fastsearch.js
@@ -38,11 +38,6 @@ window.onload = function () {
xhr.send();
}
-
-function itemGen(name, link) {
- return `
`
-}
-
function activeToggle() {
document.activeElement.parentElement.classList.toggle("focus")
}
@@ -57,23 +52,25 @@ function reset() {
sInput.onkeyup = function (e) {
// run a search query (for "term") every time a letter is typed
// in the search box
- const results = fuse.search(this.value.trim()); // the actual query being run using fuse.js
+ if (fuse) {
+ const results = fuse.search(this.value.trim()); // the actual query being run using fuse.js
+ if (results.length !== 0) {
+ // build our html if result exists
+ let resultSet = ''; // our results bucket
- if (results.length !== 0) {
- // build our html if result exists
- let resultSet = ''; // our results bucket
+ for (let item in results) {
+ resultSet += `` +
+ ``
+ }
- for (let item in results) {
- resultSet = resultSet + itemGen(results[item].item.title, results[item].item.permalink)
+ resList.innerHTML = resultSet;
+ resultsAvailable = true;
+ first = resList.firstChild;
+ last = resList.lastChild;
+ } else {
+ resultsAvailable = false;
+ resList.innerHTML = '';
}
-
- resList.innerHTML = resultSet;
- resultsAvailable = true;
- first = resList.firstChild;
- last = resList.lastChild;
- } else {
- resultsAvailable = false;
- resList.innerHTML = '';
}
}