mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
[search] fix partial matches overwriting full matches (#11958)
This commit is contained in:
parent
7f582a56ba
commit
1e4f80d7a4
@ -33,6 +33,8 @@ Features added
|
|||||||
Bugs fixed
|
Bugs fixed
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
* #11958: HTML Search: Fix partial matches overwriting full matches.
|
||||||
|
Patch by William Lachance.
|
||||||
* #11944: Use anchor in search preview.
|
* #11944: Use anchor in search preview.
|
||||||
Patch by Will Lachance.
|
Patch by Will Lachance.
|
||||||
* #11668: Raise a useful error when ``theme.conf`` is missing.
|
* #11668: Raise a useful error when ``theme.conf`` is missing.
|
||||||
|
@ -477,14 +477,18 @@ const Search = {
|
|||||||
// add support for partial matches
|
// add support for partial matches
|
||||||
if (word.length > 2) {
|
if (word.length > 2) {
|
||||||
const escapedWord = _escapeRegExp(word);
|
const escapedWord = _escapeRegExp(word);
|
||||||
Object.keys(terms).forEach((term) => {
|
if (!terms.hasOwnProperty(word)) {
|
||||||
if (term.match(escapedWord) && !terms[word])
|
Object.keys(terms).forEach((term) => {
|
||||||
arr.push({ files: terms[term], score: Scorer.partialTerm });
|
if (term.match(escapedWord))
|
||||||
});
|
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 (!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
|
// no match but word was a required one
|
||||||
|
@ -21,7 +21,7 @@ describe('Basic html theme search', function() {
|
|||||||
"<no title>",
|
"<no title>",
|
||||||
"",
|
"",
|
||||||
null,
|
null,
|
||||||
2,
|
5,
|
||||||
"index.rst"
|
"index.rst"
|
||||||
]];
|
]];
|
||||||
expect(Search.performTermsSearch(searchterms, excluded, terms, titleterms)).toEqual(hits);
|
expect(Search.performTermsSearch(searchterms, excluded, terms, titleterms)).toEqual(hits);
|
||||||
|
Loading…
Reference in New Issue
Block a user