Skip to content

Commit 4b7a2c3

Browse files
jayaddisonpicnixz
andauthored
[search] refactor Search.query into separate functions (sphinx-doc#12229)
Co-authored-by: Bénédikt Tran <[email protected]>
1 parent de1c4d7 commit 4b7a2c3

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

sphinx/themes/basic/static/searchtools.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -268,16 +268,7 @@ const Search = {
268268
else Search.deferQuery(query);
269269
},
270270

271-
/**
272-
* execute search (requires search index to be loaded)
273-
*/
274-
query: (query) => {
275-
const filenames = Search._index.filenames;
276-
const docNames = Search._index.docnames;
277-
const titles = Search._index.titles;
278-
const allTitles = Search._index.alltitles;
279-
const indexEntries = Search._index.indexentries;
280-
271+
_parseQuery: (query) => {
281272
// stem the search terms and add them to the correct list
282273
const stemmer = new Stemmer();
283274
const searchTerms = new Set();
@@ -313,6 +304,19 @@ const Search = {
313304
// console.info("required: ", [...searchTerms]);
314305
// console.info("excluded: ", [...excludedTerms]);
315306

307+
return [query, searchTerms, excludedTerms, highlightTerms, objectTerms];
308+
},
309+
310+
/**
311+
* execute search (requires search index to be loaded)
312+
*/
313+
_performSearch: (query, searchTerms, excludedTerms, highlightTerms, objectTerms) => {
314+
const filenames = Search._index.filenames;
315+
const docNames = Search._index.docnames;
316+
const titles = Search._index.titles;
317+
const allTitles = Search._index.alltitles;
318+
const indexEntries = Search._index.indexentries;
319+
316320
// Collect multiple result groups to be sorted separately and then ordered.
317321
// Each is an array of [docname, title, anchor, descr, score, filename].
318322
const normalResults = [];
@@ -394,7 +398,12 @@ const Search = {
394398
return acc;
395399
}, []);
396400

397-
results = results.reverse();
401+
return results.reverse();
402+
},
403+
404+
query: (query) => {
405+
const searchParameters = Search._parseQuery(query);
406+
const results = Search._performSearch(...searchParameters);
398407

399408
// for debugging
400409
//Search.lastresults = results.slice(); // a copy

0 commit comments

Comments
 (0)