@@ -187,7 +187,8 @@ const Search = {
187187 if ( Search . _queued_query !== null ) {
188188 const query = Search . _queued_query ;
189189 Search . _queued_query = null ;
190- Search . query ( query ) ;
190+ let { results, searchTerms, highlightTerms } = Search . query ( query ) ;
191+ _displayNextItem ( results , results . length , searchTerms , highlightTerms ) ;
191192 }
192193 } ,
193194
@@ -235,8 +236,12 @@ const Search = {
235236 Search . startPulse ( ) ;
236237
237238 // index already loaded, the browser was quick!
238- if ( Search . hasIndex ( ) ) Search . query ( query ) ;
239- else Search . deferQuery ( query ) ;
239+ if ( Search . hasIndex ( ) ) {
240+ let { results, searchTerms, highlightTerms } = Search . query ( query ) ;
241+ _displayNextItem ( results , results . length , searchTerms , highlightTerms ) ;
242+ } else {
243+ Search . deferQuery ( query ) ;
244+ }
240245 } ,
241246
242247 /**
@@ -367,8 +372,7 @@ const Search = {
367372 //Search.lastresults = results.slice(); // a copy
368373 // console.info("search results:", Search.lastresults);
369374
370- // print the results
371- _displayNextItem ( results , results . length , searchTerms , highlightTerms ) ;
375+ return { results, searchTerms, highlightTerms } ;
372376 } ,
373377
374378 /**
@@ -463,17 +467,23 @@ const Search = {
463467 { files : terms [ word ] , score : Scorer . term } ,
464468 { files : titleTerms [ word ] , score : Scorer . title } ,
465469 ] ;
470+
466471 // add support for partial matches
467472 if ( word . length > 2 ) {
468473 const escapedWord = _escapeRegExp ( word ) ;
469- Object . keys ( terms ) . forEach ( ( term ) => {
470- if ( term . match ( escapedWord ) && ! terms [ word ] )
471- arr . push ( { files : terms [ term ] , score : Scorer . partialTerm } ) ;
472- } ) ;
473- Object . keys ( titleTerms ) . forEach ( ( term ) => {
474- if ( term . match ( escapedWord ) && ! titleTerms [ word ] )
475- arr . push ( { files : titleTerms [ word ] , score : Scorer . partialTitle } ) ;
476- } ) ;
474+ if ( ! terms . hasOwnProperty ( word ) ) {
475+ Object . keys ( terms ) . forEach ( ( term ) => {
476+ if ( term . match ( escapedWord ) ) {
477+ arr . push ( { files : terms [ term ] , score : Scorer . partialTerm } ) ;
478+ }
479+ } ) ;
480+ }
481+ if ( ! titleTerms . hasOwnProperty ( word ) ) {
482+ Object . keys ( titleTerms ) . forEach ( ( term ) => {
483+ if ( term . match ( escapedWord ) )
484+ arr . push ( { files : titleTerms [ word ] , score : Scorer . partialTitle } ) ;
485+ } ) ;
486+ }
477487 }
478488
479489 // no match but word was a required one
@@ -496,9 +506,13 @@ const Search = {
496506
497507 // create the mapping
498508 files . forEach ( ( file ) => {
499- if ( fileMap . has ( file ) && fileMap . get ( file ) . indexOf ( word ) === - 1 )
500- fileMap . get ( file ) . push ( word ) ;
501- else fileMap . set ( file , [ word ] ) ;
509+ if ( fileMap . has ( file ) ) {
510+ if ( fileMap . get ( file ) . indexOf ( word ) === - 1 ) {
511+ fileMap . get ( file ) . push ( word ) ;
512+ }
513+ } else {
514+ fileMap . set ( file , [ word ] ) ;
515+ }
502516 } ) ;
503517 } ) ;
504518
0 commit comments