Use Map instead of object for flat flexsearch results

This commit is contained in:
Michael Schnerring 2021-10-15 15:16:33 +02:00
parent a3a6365817
commit a409d55365
1 changed files with 4 additions and 5 deletions

View File

@ -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);