From a409d55365839e4afd9e2d38e0ce826b0f914887 Mon Sep 17 00:00:00 2001 From: Michael Schnerring <3743342+schnerring@users.noreply.github.com> Date: Fri, 15 Oct 2021 15:16:33 +0200 Subject: [PATCH] Use Map instead of object for flat flexsearch results --- assets/js/index.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/assets/js/index.js b/assets/js/index.js index 8290ac4..61d9aa8 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -124,18 +124,17 @@ Source: var results = index.search(searchQuery, {limit: maxResult, enrich: true}); // flatten results since index.search() returns results for each indexed field - const flatResults = {}; // keyed by href to dedupe results + const flatResults = new Map(); // keyed by href to dedupe results for (const result of results.flatMap(r => r.result)) { - flatResults[result.doc.href] = result.doc; + if (flatResults.has(result.doc.href)) continue; + flatResults.set(result.doc.href, result.doc); } suggestions.innerHTML = ""; suggestions.classList.remove('d-none'); // construct a list of suggestions - for(const href in flatResults) { - const doc = flatResults[href]; - + for(const [href, doc] of flatResults) { const entry = document.createElement('div'); suggestions.appendChild(entry);