Use Map instead of object for flat flexsearch results
This commit is contained in:
parent
a3a6365817
commit
a409d55365
|
@ -124,18 +124,17 @@ Source:
|
||||||
var results = index.search(searchQuery, {limit: maxResult, enrich: true});
|
var results = index.search(searchQuery, {limit: maxResult, enrich: true});
|
||||||
|
|
||||||
// flatten results since index.search() returns results for each indexed field
|
// 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)) {
|
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.innerHTML = "";
|
||||||
suggestions.classList.remove('d-none');
|
suggestions.classList.remove('d-none');
|
||||||
|
|
||||||
// construct a list of suggestions
|
// construct a list of suggestions
|
||||||
for(const href in flatResults) {
|
for(const [href, doc] of flatResults) {
|
||||||
const doc = flatResults[href];
|
|
||||||
|
|
||||||
const entry = document.createElement('div');
|
const entry = document.createElement('div');
|
||||||
suggestions.appendChild(entry);
|
suggestions.appendChild(entry);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue