Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML Search: Fix multiple term matching edge case #11960

Merged
merged 7 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
HTML Search: Fix multiple term matching edge case
  • Loading branch information
wlach committed Mar 3, 2024
commit 70b313ddb88cc2851bebe4bc3d6d7c7b3fbabdf7
10 changes: 7 additions & 3 deletions sphinx/themes/basic/static/searchtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,13 @@ 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)) {
if (fileMap.get(file).indexOf(word) === -1) {
fileMap.get(file).push(word);
}
} else {
fileMap.set(file, [word]);
}
wlach marked this conversation as resolved.
Show resolved Hide resolved
});
});

Expand Down
30 changes: 30 additions & 0 deletions tests/js/searchtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,36 @@ 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: {
picnixz marked this conversation as resolved.
Show resolved Hide resolved
'Main Page': [[0, 'main-page']],
},
docnames:["index"],
filenames:["index.rst"],
indexentries:{},
objects:{},
objtypes: {},
objnames: {},
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