[search] fix partial matches overwriting full matches (#11958)

This commit is contained in:
Will Lachance 2024-03-03 09:18:07 -05:00 committed by GitHub
parent 7f582a56ba
commit 1e4f80d7a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 9 deletions

View File

@ -33,6 +33,8 @@ Features added
Bugs fixed
----------
* #11958: HTML Search: Fix partial matches overwriting full matches.
Patch by William Lachance.
* #11944: Use anchor in search preview.
Patch by Will Lachance.
* #11668: Raise a useful error when ``theme.conf`` is missing.

View File

@ -477,14 +477,18 @@ const Search = {
// add support for partial matches
if (word.length > 2) {
const escapedWord = _escapeRegExp(word);
Object.keys(terms).forEach((term) => {
if (term.match(escapedWord) && !terms[word])
arr.push({ files: terms[term], score: Scorer.partialTerm });
});
Object.keys(titleTerms).forEach((term) => {
if (term.match(escapedWord) && !titleTerms[word])
arr.push({ files: titleTerms[word], score: Scorer.partialTitle });
});
if (!terms.hasOwnProperty(word)) {
Object.keys(terms).forEach((term) => {
if (term.match(escapedWord))
arr.push({ files: terms[term], score: Scorer.partialTerm });
});
}
if (!titleTerms.hasOwnProperty(word)) {
Object.keys(titleTerms).forEach((term) => {
if (term.match(escapedWord))
arr.push({ files: titleTerms[word], score: Scorer.partialTitle });
});
}
}
// no match but word was a required one

View File

@ -21,7 +21,7 @@ describe('Basic html theme search', function() {
"<no title>",
"",
null,
2,
5,
"index.rst"
]];
expect(Search.performTermsSearch(searchterms, excluded, terms, titleterms)).toEqual(hits);