Skip to content

Commit

Permalink
Merge pull request #10236 from calebchiam/master
Browse files Browse the repository at this point in the history
Fixing duplicate search results bug (5.0)
  • Loading branch information
tk0miya committed Mar 6, 2022
2 parents db885ef + ca0d432 commit 262240d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions sphinx/themes/basic/static/searchtools.js
Expand Up @@ -292,6 +292,20 @@ const Search = {
return leftScore > rightScore ? 1 : -1;
});

// remove duplicate search results
// note the reversing of results, so that in the case of duplicates, the highest-scoring entry is kept
let seen = new Set();
results = results.reverse().reduce((acc, result) => {
let resultStr = result.slice(0, 4).concat([result[5]]).map(v => String(v)).join(',');
if (!seen.has(resultStr)) {
acc.push(result);
seen.add(resultStr);
}
return acc;
}, []);

results = results.reverse();

// for debugging
//Search.lastresults = results.slice(); // a copy
// console.info("search results:", Search.lastresults);
Expand Down

0 comments on commit 262240d

Please sign in to comment.