Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions sphinx/themes/basic/static/searchtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,12 +478,12 @@ const Search = {
if (word.length > 2) {
const escapedWord = _escapeRegExp(word);
Object.keys(terms).forEach((term) => {
if (term.match(escapedWord) && !terms[word])
if (term.match(escapedWord) && terms[word] === undefined)
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 (term.match(escapedWord) && titleTerms[word] === undefined)
arr.push({ files: titleTerms[term], score: Scorer.partialTitle });
});
}

Expand Down
27 changes: 26 additions & 1 deletion tests/js/searchtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,32 @@ describe('Basic html theme search', function() {
"<no title>",
"",
null,
2,
5,
"index.rst"
]];
expect(Search.performTermsSearch(searchterms, excluded, terms, titleterms)).toEqual(hits);
});

it('should partially-match "sphinx" when in title index', function() {
index = {
docnames:["index"],
filenames:["index.rst"],
terms:{'useful': 0, 'utilities': 0},
titles:["sphinx_utils module"],
titleterms:{'sphinx_utils': 0}
}
Search.setIndex(index);
searchterms = ['sphinx'];
excluded = [];
terms = index.terms;
titleterms = index.titleterms;

hits = [[
"index",
"sphinx_utils module",
"",
null,
7,
"index.rst"
]];
expect(Search.performTermsSearch(searchterms, excluded, terms, titleterms)).toEqual(hits);
Expand Down