@@ -350,32 +350,35 @@ var Search = Control.extend({
350350 var searchTerm = value . toLowerCase ( ) ;
351351 var self = this ;
352352 return this . searchEnginePromise . then ( function ( searchEngine ) {
353- return searchEngine
354- //run the search
355- . query ( function ( q ) {
356353
357- if ( searchTerm . indexOf ( 'can-' ) > - 1 ) { // If the search term includes “can-”
354+ //run the search
355+ var queryResults = searchEngine . query ( function ( q ) {
358356
359- // look for an exact match and apply a large positive boost
360- q . term ( searchTerm , { usePipeline : true , boost : 375 } ) ;
357+ if ( searchTerm . indexOf ( 'can-' ) > - 1 ) { // If the search term includes “can-”
361358
362- } else {
363- // add “can-”, look for an exact match in the title field, and apply a positive boost
364- q . term ( 'can-' + searchTerm , { usePipeline : false , fields : [ 'title' ] , boost : 12 } ) ;
365- }
359+ // look for an exact match and apply a large positive boost
360+ q . term ( searchTerm , { usePipeline : true , boost : 375 } ) ;
361+
362+ } else {
363+ // add “can-”, look for an exact match in the title field, and apply a positive boost
364+ q . term ( 'can-' + searchTerm , { usePipeline : false , fields : [ 'title' ] , boost : 12 } ) ;
366365
367366 // look for terms that match the beginning or end of this query
368367 q . term ( '*' + searchTerm + '*' , { usePipeline : false } ) ;
368+ }
369+
370+ // look for matches in any of the fields and apply a medium positive boost
371+ var split = searchTerm . split ( lunr . tokenizer . separator ) ;
372+ split . forEach ( function ( term ) {
373+ q . term ( term , { usePipeline : false , fields : q . allFields , boost : 10 } ) ;
374+ q . term ( term + '*' , { usePipeline : false , fields : q . allFields } ) ;
375+ } ) ;
376+ } ) ;
377+
378+ //convert the results into a searchMap subset
379+ var mappedResults = queryResults . map ( function ( result ) { return self . searchMap [ result . ref ] } ) ;
369380
370- // look for matches in any of the fields and apply a medium positive boost
371- var split = searchTerm . split ( lunr . tokenizer . separator ) ;
372- split . forEach ( function ( term ) {
373- q . term ( term , { usePipeline : false , fields : q . allFields , boost : 10 } ) ;
374- q . term ( term + '*' , { usePipeline : false , fields : q . allFields } ) ;
375- } ) ;
376- } )
377- //convert the results into a searchMap subset
378- . map ( function ( result ) { return self . searchMap [ result . ref ] } ) ;
381+ return mappedResults ;
379382 } ) ;
380383 } ,
381384
0 commit comments