Skip to content

Commit bfce4f5

Browse files
jayaddisonwlach
andauthored
[HTML search] include partially-matched document titles in search results (#12041)
Co-authored-by: William Lachance <[email protected]>
1 parent 04bd0df commit bfce4f5

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ Bugs fixed
139139
* #10786: improve the error message when a file to be copied (e.g., an asset)
140140
is removed during Sphinx execution.
141141
Patch by Bénédikt Tran.
142+
* #12040: HTML Search: Ensure that document titles that are partially-matched by
143+
the user search query are included in search results.
144+
Patch by James Addison.
142145

143146
Testing
144147
-------

sphinx/themes/basic/static/searchtools.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ const Search = {
508508
if (!titleTerms.hasOwnProperty(word)) {
509509
Object.keys(titleTerms).forEach((term) => {
510510
if (term.match(escapedWord))
511-
arr.push({ files: titleTerms[word], score: Scorer.partialTitle });
511+
arr.push({ files: titleTerms[term], score: Scorer.partialTitle });
512512
});
513513
}
514514
}

tests/js/searchtools.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,31 @@ describe('Basic html theme search', function() {
5454
expect(Search.performTermsSearch(searchterms, excluded, terms, titleterms)).toEqual(hits);
5555
});
5656

57+
it('should partially-match "sphinx" when in title index', function() {
58+
index = {
59+
docnames:["index"],
60+
filenames:["index.rst"],
61+
terms:{'useful': 0, 'utilities': 0},
62+
titles:["sphinx_utils module"],
63+
titleterms:{'sphinx_utils': 0}
64+
}
65+
Search.setIndex(index);
66+
searchterms = ['sphinx'];
67+
excluded = [];
68+
terms = index.terms;
69+
titleterms = index.titleterms;
70+
71+
hits = [[
72+
"index",
73+
"sphinx_utils module",
74+
"",
75+
null,
76+
7,
77+
"index.rst"
78+
]];
79+
expect(Search.performTermsSearch(searchterms, excluded, terms, titleterms)).toEqual(hits);
80+
});
81+
5782
});
5883

5984
});

0 commit comments

Comments
 (0)