@@ -335,7 +335,11 @@ var Search = Control.extend({
335
335
336
336
for ( var itemKey in searchMap ) {
337
337
if ( searchMap . hasOwnProperty ( itemKey ) ) {
338
- this . add ( searchMap [ itemKey ] )
338
+ var item = searchMap [ itemKey ] ;
339
+ if ( ! item . title ) {
340
+ item . title = item . name ;
341
+ }
342
+ this . add ( item ) ;
339
343
}
340
344
}
341
345
} ) ;
@@ -349,6 +353,7 @@ var Search = Control.extend({
349
353
// takes a value and returns a map of all relevant search items
350
354
searchEngineSearch : function ( value ) {
351
355
var searchTerm = value . toLowerCase ( ) ;
356
+ console . log ( 'searchTerm:' , searchTerm ) ;
352
357
var self = this ;
353
358
return this . searchEnginePromise . then ( function ( searchEngine ) {
354
359
@@ -362,17 +367,17 @@ var Search = Control.extend({
362
367
363
368
} else {
364
369
// add “can-”, look for an exact match in the title field, and apply a positive boost
365
- q . term ( 'can-' + searchTerm , { usePipeline : false , fields : [ 'title' ] , boost : 12 } ) ;
370
+ q . term ( 'can-' + searchTerm , { usePipeline : false , boost : 12 } ) ;
366
371
367
372
// look for terms that match the beginning or end of this query
368
- q . term ( '*' + searchTerm + '*' , { usePipeline : false } ) ;
373
+ q . term ( searchTerm , { usePipeline : false , wildcard : lunr . Query . wildcard . LEADING | lunr . Query . wildcard . TRAILING } ) ;
369
374
}
370
375
371
376
// look for matches in any of the fields and apply a medium positive boost
372
377
var split = searchTerm . split ( lunr . tokenizer . separator ) ;
373
378
split . forEach ( function ( term ) {
374
379
q . term ( term , { usePipeline : false , fields : q . allFields , boost : 10 } ) ;
375
- q . term ( term + '*' , { usePipeline : false , fields : q . allFields } ) ;
380
+ q . term ( term , { usePipeline : false , fields : q . allFields , wildcard : lunr . Query . wildcard . TRAILING } ) ;
376
381
} ) ;
377
382
} ) ;
378
383
@@ -382,37 +387,6 @@ var Search = Control.extend({
382
387
return mappedResults ;
383
388
} ) ;
384
389
} ,
385
-
386
- //function formatSearchTerm
387
- // replace colons because they can confuse the search engine
388
- // if they're not part of a field search
389
- // @param term
390
- formatSearchTerm : function ( term ) {
391
- var colonParts = term . split ( ":" ) ,
392
- wildcardChar = "*"
393
-
394
- //go ahead and leave if no colons found
395
- if ( colonParts . length === 1 ) {
396
- return wildcardChar + term + wildcardChar ;
397
- }
398
-
399
- var colonReplacement = "*" ,
400
- fields = [ "name" , "title" , "description" , "url" ] ,
401
- hasFieldSearch = colonParts . length > 1 ,
402
- fieldToSearch = hasFieldSearch ? colonParts . shift ( ) : null ,
403
- isFieldToSearchInFields = fields . indexOf ( fieldToSearch ) >= 0 ;
404
-
405
- term = colonParts . join ( colonReplacement ) + wildcardChar ;
406
-
407
- if ( isFieldToSearchInFields ) {
408
- term = fieldToSearch + ":" + term ;
409
- } else {
410
- term = wildcardChar + term ;
411
- }
412
-
413
- return term ;
414
- } ,
415
-
416
390
// ---- END SEARCHING / PARSING ---- //
417
391
418
392
0 commit comments