Skip to content

Commit ee188f7

Browse files
committed
Keep anchor, de-duplicate on less keys
1 parent 96336be commit ee188f7

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

sphinx/themes/basic/static/searchtools.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ const Search = {
314314
results.push([
315315
docNames[file],
316316
isDocumentTitle ? title : `${titles[file]} > ${title}`,
317-
isDocumentTitle ? "" : anchor, // don't provide an anchor if we matched on the exact document title (creates duplicates below)
317+
anchor,
318318
null,
319319
score,
320320
filenames[file],
@@ -371,7 +371,8 @@ const Search = {
371371
// note the reversing of results, so that in the case of duplicates, the highest-scoring entry is kept
372372
let seen = new Set();
373373
results = results.reverse().reduce((acc, result) => {
374-
let resultStr = result.slice(0, 4).concat([result[5]]).map(v => String(v)).join(',');
374+
// de-duplicate on file, title, and description
375+
let resultStr = result.slice(0, 2).concat(result[3]).map(v => String(v)).join(',');
375376
if (!seen.has(resultStr)) {
376377
acc.push(result);
377378
seen.add(resultStr);

tests/js/searchtools.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('Basic html theme search', function() {
7676
let { results } = Search.query('main page');
7777
// should only be one result
7878
expect(results).toEqual([
79-
[ 'index', 'Main Page', '', null, 100, 'index.rst' ],
79+
[ 'index', 'Main Page', '#main-page', null, 100, 'index.rst' ],
8080
]);
8181
});
8282
})

0 commit comments

Comments
 (0)