Skip to content

Instantly share code, notes, and snippets.

@wlach
Created February 7, 2024 14:51
Show Gist options
  • Save wlach/74124608c2113d8eb9737cdced4762db to your computer and use it in GitHub Desktop.
Save wlach/74124608c2113d8eb9737cdced4762db to your computer and use it in GitHub Desktop.
diff --git a/sphinx/themes/basic/static/searchtools.js b/sphinx/themes/basic/static/searchtools.js
index 8bb1af5a4..42bc8536f 100644
--- a/sphinx/themes/basic/static/searchtools.js
+++ b/sphinx/themes/basic/static/searchtools.js
@@ -496,9 +496,11 @@ const Search = {
// create the mapping
files.forEach((file) => {
- if (fileMap.has(file) && fileMap.get(file).indexOf(word) === -1)
+ if (!fileMap.has(file)) {
+ fileMap.set(file, [word]);
+ } else if (fileMap.get(file).indexOf(word) === -1) {
fileMap.get(file).push(word);
- else fileMap.set(file, [word]);
+ }
});
});
diff --git a/tests/js/searchtools.js b/tests/js/searchtools.js
index c9e0c43d3..7110e1b30 100644
--- a/tests/js/searchtools.js
+++ b/tests/js/searchtools.js
@@ -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,
+ 7,
+ 'index.rst']];
+ expect(Search.performTermsSearch(searchterms, excluded, terms, titleterms)).toEqual(hits);
+ });
+
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment