Skip to content

Commit

Permalink
Use Map instead of object for flat flexsearch results
Browse files Browse the repository at this point in the history
  • Loading branch information
schnerring committed Oct 15, 2021
1 parent a3a6365 commit a409d55
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit a409d55

Please sign in to comment.