if (Meteor.isServer) {
SearchSource.defineSource('courses', function(searchText, options) {
var options = {
fields: {'catalog':1, 'titleLong':1, 'catalogNbr':1},
limit: 10
};
if(searchText) {
var regExp = buildRegExp(searchText);
var selector = {$or: [
{titleLong: { $regex: regExp } },
{catalog: { $regex: regExp } },
{catalogNbr: { $regex: regExp } }
]}
return Courses.find(selector, options).fetch();
} else {
console.log("couldn't find anything that suits the query");
console.log("query:", searchText);
return Courses.find({}, options).fetch();
}
});
function buildRegExp(searchText) {
var words = searchText.trim().split(/[ \-\:]+/);
var exps = _.map(words, function(word) {
return "(?=.*" + word + ")";
});
var fullExp = exps.join('') + ".+";
return new RegExp(fullExp, "i");
}
}
query = "intro algo" matches with "introduction to analysis of algorithms"
If you go to the demo url, you will see that although the document is found, it's rendered in a weird way.
Type into algo first, then press any function key like alt, cmd, or ctrl. You will see that the result disappears and appears intermittently.
Set breakpoints inside getData() and you will see that it returns an empty object even though there's fetch data.
Demo page: http://cornellcoursereview.meteor.com/
My code:
query = "intro algo" matches with "introduction to analysis of algorithms" If you go to the demo url, you will see that although the document is found, it's rendered in a weird way.
Type
into algo
first, then press any function key likealt
,cmd
, orctrl
. You will see that the result disappears and appears intermittently.Set breakpoints inside
getData()
and you will see that it returns an empty object even though there's fetch data.