Vulcan/packages/nova-search/lib/parameters.js

25 lines
821 B
JavaScript
Raw Normal View History

2016-08-08 11:18:21 +09:00
import Telescope from 'meteor/nova:lib';
2016-07-22 10:25:17 +09:00
import escapeStringRegexp from 'escape-string-regexp';
import { Callbacks } from 'meteor/nova:core';
2016-07-22 10:25:17 +09:00
function addSearchQueryParameter (parameters, terms) {
if(!!terms.query) {
2016-07-22 10:25:17 +09:00
const query = escapeStringRegexp(terms.query);
parameters = Telescope.utils.deepExtend(true, parameters, {
selector: {
$or: [
2016-07-22 10:25:17 +09:00
{title: {$regex: query, $options: 'i'}},
{url: {$regex: query, $options: 'i'}},
2016-05-07 18:09:39 +09:00
// note: we cannot search the body field because it's not published
// to the client. If we did, we'd get different result sets on
// client and server
2016-07-22 10:25:17 +09:00
{excerpt: {$regex: query, $options: 'i'}}
]
}
});
}
return parameters;
}
Callbacks.add("posts.parameters", addSearchQueryParameter);