Skip to content

Commit 949e131

Browse files
committed
Further work to clarify
1 parent 772119c commit 949e131

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

sphinx/themes/basic/static/searchtools.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
if (typeof Scorer === "undefined") {
1717
var Scorer = {
1818
// Implement the following function to further tweak the score for each result
19-
// The function takes a result array [docname, title, anchor, descr, score, filename]
19+
// The function takes a result array [docname, title, anchor, anchorIsDocumentTitle, descr, score]
2020
// and returns the new score.
2121
/*
2222
score: result => {
23-
const [docname, title, anchor, descr, score, filename] = result
23+
const [docname, title, anchor, anchorIsDocumentTitle, descr, score] = result
2424
return score
2525
},
2626
*/
@@ -64,7 +64,7 @@ const _displayItem = (item, searchTerms, highlightTerms) => {
6464
const showSearchSummary = DOCUMENTATION_OPTIONS.SHOW_SEARCH_SUMMARY;
6565
const contentRoot = document.documentElement.dataset.content_root;
6666

67-
const [docName, title, _isDocumentTitle, anchor, descr, score] = item;
67+
const [docName, title, anchor, _anchorIsDocumentTitle, descr, score] = item;
6868

6969
let listItem = document.createElement("li");
7070
let requestUrl;
@@ -309,13 +309,13 @@ const Search = {
309309
if (title.toLowerCase().trim().includes(queryLower) && (queryLower.length >= title.length/2)) {
310310
for (const [file, id] of foundTitles) {
311311
let score = Math.round(100 * queryLower.length / title.length)
312-
let isDocumentTitle = titles[file] === title
312+
let anchorIsDocumentTitle = titles[file] === title
313313
let anchor = id ? `#${id}` : ""
314314
results.push([
315315
docNames[file],
316-
isDocumentTitle ? title : `${titles[file]} > ${title}`,
317-
isDocumentTitle,
316+
anchorIsDocumentTitle ? title : `${titles[file]} > ${title}`,
318317
anchor,
318+
anchorIsDocumentTitle,
319319
null,
320320
score,
321321
filenames[file],
@@ -376,8 +376,10 @@ const Search = {
376376
// de-duplicate on file, title, description, and (if not the title section) anchor
377377
// we omit the anchor for the title section as otherwise we'll get two entries for the
378378
// entire document
379-
let [docname, title, isDocumentTitle, anchor, descr, score, filename] = result;
380-
let resultStr = [docname, title, isDocumentTitle ? '' : anchor, descr].map(v => String(v)).join(',');
379+
let [docname, title, anchor, anchorIsDocumentTitle, descr, score, filename] = result;
380+
// Consider a link to the anchor representing the document title equivalent to a link
381+
// to the document without an anchor
382+
let resultStr = [docname, title, anchorIsDocumentTitle ? '' : anchor, descr].map(v => String(v)).join(',');
381383
if (!seen.has(resultStr)) {
382384
acc.push(result);
383385
seen.add(resultStr);
@@ -451,8 +453,8 @@ const Search = {
451453
results.push([
452454
docNames[match[0]],
453455
fullname,
454-
false,
455456
"#" + anchor,
457+
false,
456458
descr,
457459
score,
458460
filenames[match[0]],
@@ -563,8 +565,8 @@ const Search = {
563565
results.push([
564566
docNames[file],
565567
titles[file],
566-
false,
567568
"",
569+
false,
568570
null,
569571
score,
570572
filenames[file],

tests/js/searchtools.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ describe('Basic html theme search', function() {
1919
hits = [[
2020
"index",
2121
"<no title>",
22-
false,
2322
"",
23+
false,
2424
null,
2525
5,
2626
"index.rst"
@@ -77,7 +77,7 @@ describe('Basic html theme search', function() {
7777
let { results } = Search.query('main page');
7878
// should only be one result
7979
expect(results).toEqual([
80-
[ 'index', 'Main Page', true, '#main-page', null, 100, 'index.rst' ],
80+
[ 'index', 'Main Page', '#main-page', true, null, 100, 'index.rst' ],
8181
]);
8282
});
8383
})

0 commit comments

Comments
 (0)