Skip to content

Commit 8fcfc22

Browse files
committed
Fix duplicate search results
We currently list the same page multiple times if, for example, both the title and content search match it. Since the preview is always the same, this is not very helpful.
1 parent ae51974 commit 8fcfc22

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

sphinx/themes/basic/static/searchtools.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,14 @@ const Search = {
362362

363363
// remove duplicate search results
364364
// note the reversing of results, so that in the case of duplicates, the highest-scoring entry is kept
365+
// this may remove some entries which refer to slightly different parts of the same document
366+
// but this is a tradeoff to avoid showing the same document multiple times (the preview always looks the
367+
// same, so this is not very useful)
365368
let seen = new Set();
366369
results = results.reverse().reduce((acc, result) => {
367-
let resultStr = result.slice(0, 4).concat([result[5]]).map(v => String(v)).join(',');
368-
if (!seen.has(resultStr)) {
370+
if (!seen.has(result[0])) {
369371
acc.push(result);
370-
seen.add(resultStr);
372+
seen.add(result[0]);
371373
}
372374
return acc;
373375
}, []);

0 commit comments

Comments
 (0)