Skip to content

Commit

Permalink
[search] fix multiple term matching edge case (#11960)
Browse files Browse the repository at this point in the history
  • Loading branch information
wlach committed Mar 3, 2024
1 parent 1e4f80d commit ae51974
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Features added
Bugs fixed
----------

* #11959: Fix multiple term matching when word appears in both title and document.
Patch by Will Lachance.
* #11958: HTML Search: Fix partial matches overwriting full matches.
Patch by William Lachance.
* #11944: Use anchor in search preview.
Expand Down
5 changes: 2 additions & 3 deletions sphinx/themes/basic/static/searchtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,8 @@ const Search = {

// create the mapping
files.forEach((file) => {
if (fileMap.has(file) && fileMap.get(file).indexOf(word) === -1)
fileMap.get(file).push(word);
else fileMap.set(file, [word]);
if (!fileMap.has(file)) fileMap.set(file, [word]);
else if (fileMap.get(file).indexOf(word) === -1) fileMap.get(file).push(word);
});
});

Expand Down
27 changes: 27 additions & 0 deletions tests/js/searchtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,33 @@ describe('Basic html theme search', function() {
expect(Search.performTermsSearch(searchterms, excluded, terms, titleterms)).toEqual(hits);
});

it('should be able to search for multiple terms', function() {
index = {
alltitles: {
'Main Page': [[0, 'main-page']],
},
docnames:["index"],
filenames:["index.rst"],
terms:{main:0, page:0},
titles:["Main Page"],
titleterms:{ main:0, page:0 }
}
Search.setIndex(index);

searchterms = ['main', 'page'];
excluded = [];
terms = index.terms;
titleterms = index.titleterms;
hits = [[
'index',
'Main Page',
'',
null,
15,
'index.rst']];
expect(Search.performTermsSearch(searchterms, excluded, terms, titleterms)).toEqual(hits);
});

});

});
Expand Down

0 comments on commit ae51974

Please sign in to comment.