[search] fix multiple term matching edge case (#11960)

This commit is contained in:
Will Lachance 2024-03-03 12:01:10 -05:00 committed by GitHub
parent 1e4f80d7a4
commit ae51974e21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 3 deletions

View File

@ -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.

View File

@ -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);
});
});

View File

@ -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);
});
});
});