@@ -244,6 +244,7 @@ if (typeof splitQuery === "undefined") {
244244const Search = {
245245 _index : null ,
246246 _queued_query : null ,
247+ _queued_section : null ,
247248 _pulse_status : - 1 ,
248249
249250 htmlToText : ( htmlString , anchor ) => {
@@ -252,30 +253,35 @@ const Search = {
252253 htmlElement . querySelectorAll ( removalQuery ) . forEach ( ( el ) => { el . remove ( ) } ) ;
253254 }
254255 if ( anchor ) {
255- const anchorContent = htmlElement . querySelector ( `[role="main"] ${ anchor } ` ) ;
256+ const anchorContent = htmlElement . querySelector ( `.bd-article ${ anchor } ` ) ;
256257 if ( anchorContent ) return anchorContent . textContent ;
257258
258259 console . warn (
259- `Anchored content block not found. Sphinx search tries to obtain it via DOM query '[role=main] ${ anchor } '. Check your theme or template.`
260+ `Anchored content block not found. Sphinx search tries to obtain it via DOM query '.bd-article ${ anchor } '. Check your theme or template.`
260261 ) ;
261262 }
262263
263264 // if anchor not specified or not found, fall back to main content
264- const docContent = htmlElement . querySelector ( '[role="main"] ' ) ;
265+ const docContent = htmlElement . querySelector ( '.bd-article ' ) ;
265266 if ( docContent ) return docContent . textContent ;
266267
267268 console . warn (
268- "Content block not found. Sphinx search tries to obtain it via DOM query '[role=main] '. Check your theme or template."
269+ "Content block not found. Sphinx search tries to obtain it via DOM query '.bd-article '. Check your theme or template."
269270 ) ;
270271 return "" ;
271272 } ,
272273
273274 init : ( ) => {
274275 const query = new URLSearchParams ( window . location . search ) . get ( "q" ) ;
276+ const section = new URLSearchParams ( window . location . search ) . get ( "section" ) ;
277+ const select = document
278+ . querySelector ( 'select[name="section"]' ) ;
275279 document
276280 . querySelectorAll ( 'input[name="q"]' )
277281 . forEach ( ( el ) => ( el . value = query ) ) ;
278- if ( query ) Search . performSearch ( query ) ;
282+ if ( section ) select . value = section ;
283+ else select . value = "all" ;
284+ if ( query ) Search . performSearch ( query , section ) ;
279285 } ,
280286
281287 loadIndex : ( url ) =>
@@ -285,14 +291,19 @@ const Search = {
285291 Search . _index = index ;
286292 if ( Search . _queued_query !== null ) {
287293 const query = Search . _queued_query ;
294+ const section = Search . _queued_section ;
288295 Search . _queued_query = null ;
289- Search . query ( query ) ;
296+ Search . _queued_section = null ;
297+ Search . query ( query , section ) ;
290298 }
291299 } ,
292300
293301 hasIndex : ( ) => Search . _index !== null ,
294302
295- deferQuery : ( query ) => ( Search . _queued_query = query ) ,
303+ deferQuery : ( query , section ) => {
304+ Search . _queued_query = query ;
305+ Search . _queued_section = section ;
306+ } ,
296307
297308 stopPulse : ( ) => ( Search . _pulse_status = - 1 ) ,
298309
@@ -310,7 +321,7 @@ const Search = {
310321 /**
311322 * perform a search for something (or wait until index is loaded)
312323 */
313- performSearch : ( query ) => {
324+ performSearch : ( query , section ) => {
314325 // create the required interface elements
315326 const searchText = document . createElement ( "h2" ) ;
316327 searchText . textContent = _ ( "Searching" ) ;
@@ -335,8 +346,8 @@ const Search = {
335346 Search . startPulse ( ) ;
336347
337348 // index already loaded, the browser was quick!
338- if ( Search . hasIndex ( ) ) Search . query ( query ) ;
339- else Search . deferQuery ( query ) ;
349+ if ( Search . hasIndex ( ) ) Search . query ( query , section ) ;
350+ else Search . deferQuery ( query , section ) ;
340351 } ,
341352
342353 _parseQuery : ( query ) => {
@@ -475,10 +486,16 @@ const Search = {
475486 return results . reverse ( ) ;
476487 } ,
477488
478- query : ( query ) => {
489+ query : ( query , section ) => {
479490 const [ searchQuery , searchTerms , excludedTerms , highlightTerms , objectTerms ] = Search . _parseQuery ( query ) ;
480- const results = Search . _performSearch ( searchQuery , searchTerms , excludedTerms , highlightTerms , objectTerms ) ;
481- const qresults = results ;
491+ let results = Search . _performSearch ( searchQuery , searchTerms , excludedTerms , highlightTerms , objectTerms ) ;
492+
493+ // Filter results by section
494+ if ( section && section !== 'all' ) {
495+ results = results . filter ( result => {
496+ return result [ 0 ] . split ( '/' ) [ 0 ] === section ;
497+ } ) ;
498+ }
482499
483500 // for debugging
484501 //Search.lastresults = results.slice(); // a copy
0 commit comments