Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"escape-html": "^1.0.3",
"jquery": "^3.1.1",
"lodash": "^4.17.4",
"lunr": "^2.0.3",
"lunr": "^2.1.0",
"steal-stache": "^3.0.1",
"unescape-html": "^1.0.0"
},
Expand Down
43 changes: 8 additions & 35 deletions static/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,11 @@ var Search = Control.extend({

for (var itemKey in searchMap) {
if (searchMap.hasOwnProperty(itemKey)) {
this.add(searchMap[itemKey])
var item = searchMap[itemKey];
if(!item.title){
item.title = item.name;
}
this.add(item);
}
}
});
Expand All @@ -362,17 +366,17 @@ var Search = Control.extend({

} else {
// add “can-”, look for an exact match in the title field, and apply a positive boost
q.term('can-' + searchTerm, { usePipeline: false, fields: ['title'], boost: 12 });
q.term('can-' + searchTerm, { usePipeline: false, boost: 12 });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the fields property when we were testing things, but didn’t mean for this change to be committed. If it’s working then ok, but it might be useful to add back.


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

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

Expand All @@ -382,37 +386,6 @@ var Search = Control.extend({
return mappedResults;
});
},

//function formatSearchTerm
// replace colons because they can confuse the search engine
// if they're not part of a field search
// @param term
formatSearchTerm: function(term){
var colonParts = term.split(":"),
wildcardChar = "*"

//go ahead and leave if no colons found
if(colonParts.length === 1){
return wildcardChar + term + wildcardChar;
}

var colonReplacement = "*",
fields = ["name", "title", "description", "url"],
hasFieldSearch = colonParts.length > 1,
fieldToSearch = hasFieldSearch ? colonParts.shift() : null,
isFieldToSearchInFields = fields.indexOf(fieldToSearch) >= 0;

term = colonParts.join(colonReplacement) + wildcardChar;

if(isFieldToSearchInFields){
term = fieldToSearch + ":" + term;
}else{
term = wildcardChar + term;
}

return term;
},

// ---- END SEARCHING / PARSING ---- //


Expand Down