Skip to content

Commit d8938af

Browse files
authored
Merge pull request #320 from canjs/update-lunr
Update lunr
2 parents 00248c6 + 12613b6 commit d8938af

File tree

2 files changed

+9
-36
lines changed

2 files changed

+9
-36
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"escape-html": "^1.0.3",
3636
"jquery": "^3.1.1",
3737
"lodash": "^4.17.4",
38-
"lunr": "^2.0.3",
38+
"lunr": "^2.1.0",
3939
"steal-stache": "^3.0.1",
4040
"unescape-html": "^1.0.0"
4141
},

static/search.js

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,11 @@ var Search = Control.extend({
335335

336336
for (var itemKey in searchMap) {
337337
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);
339343
}
340344
}
341345
});
@@ -362,17 +366,17 @@ var Search = Control.extend({
362366

363367
} else {
364368
// 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 });
369+
q.term('can-' + searchTerm, { usePipeline: false, boost: 12 });
366370

367371
// look for terms that match the beginning or end of this query
368-
q.term('*' + searchTerm + '*', { usePipeline: false });
372+
q.term(searchTerm, { usePipeline: false, wildcard: lunr.Query.wildcard.LEADING | lunr.Query.wildcard.TRAILING });
369373
}
370374

371375
// look for matches in any of the fields and apply a medium positive boost
372376
var split = searchTerm.split(lunr.tokenizer.separator);
373377
split.forEach(function(term) {
374378
q.term(term, { usePipeline: false, fields: q.allFields, boost: 10 });
375-
q.term(term + '*', { usePipeline: false, fields: q.allFields });
379+
q.term(term, { usePipeline: false, fields: q.allFields, wildcard: lunr.Query.wildcard.TRAILING });
376380
});
377381
});
378382

@@ -382,37 +386,6 @@ var Search = Control.extend({
382386
return mappedResults;
383387
});
384388
},
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-
416389
// ---- END SEARCHING / PARSING ---- //
417390

418391

0 commit comments

Comments
 (0)