Skip to content

Commit e2695c7

Browse files
committed
HTML Search: Fix partial matches overwriting full matches
1 parent 4ef8752 commit e2695c7

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

sphinx/themes/basic/static/searchtools.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -466,14 +466,18 @@ const Search = {
466466
// add support for partial matches
467467
if (word.length > 2) {
468468
const escapedWord = _escapeRegExp(word);
469-
Object.keys(terms).forEach((term) => {
470-
if (term.match(escapedWord) && !terms[word])
471-
arr.push({ files: terms[term], score: Scorer.partialTerm });
472-
});
473-
Object.keys(titleTerms).forEach((term) => {
474-
if (term.match(escapedWord) && !titleTerms[word])
475-
arr.push({ files: titleTerms[word], score: Scorer.partialTitle });
476-
});
469+
if (!terms.hasOwnProperty(word)) {
470+
Object.keys(terms).forEach((term) => {
471+
if (term.match(escapedWord))
472+
arr.push({ files: terms[term], score: Scorer.partialTerm });
473+
});
474+
}
475+
if (!titleTerms.hasOwnProperty(word)) {
476+
Object.keys(titleTerms).forEach((term) => {
477+
if (term.match(escapedWord))
478+
arr.push({ files: titleTerms[word], score: Scorer.partialTitle });
479+
});
480+
}
477481
}
478482

479483
// no match but word was a required one

tests/js/searchtools.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('Basic html theme search', function() {
2121
"<no title>",
2222
"",
2323
null,
24-
2,
24+
5,
2525
"index.rst"
2626
]];
2727
expect(Search.performTermsSearch(searchterms, excluded, terms, titleterms)).toEqual(hits);

0 commit comments

Comments
 (0)