Vulcan/packages/telescope-search/lib/search.js

59 lines
1.3 KiB
JavaScript
Raw Normal View History

// push "search" template to primaryNav
Telescope.config.primaryNav.push({
template: 'search',
order: 100
});
2014-06-23 11:40:21 +09:00
Telescope.config.mobileNav.push({
2015-03-24 17:03:37 +09:00
template: 'search',
order: 1
});
Telescope.config.adminMenu.push({
route: 'searchLogs',
label: 'search_logs',
description: 'see_what_people_are_searching_for'
});
2015-04-11 12:25:34 +09:00
registerElementColor('.search .search-field', 'secondaryContrastColor');
2014-06-22 10:55:31 +09:00
Searches = new Meteor.Collection("searches", {
schema: new SimpleSchema({
_id: {
type: String,
optional: true
},
timestamp: {
type: Date
},
keyword: {
type: String
}
})
});
2013-11-22 14:20:47 +09:00
Meteor.startup(function() {
Searches.allow({
update: Users.isAdminById
, remove: Users.isAdminById
});
2013-11-22 14:20:47 +09:00
});
// search post list parameters
viewParameters.search = function (terms, baseParameters) {
// if query is empty, just return parameters that will result in an empty collection
2014-11-28 17:26:06 -08:00
if(typeof terms.query === 'undefined' || !terms.query)
return {find:{_id: 0}}
var parameters = Telescope.utils.deepExtend(true, baseParameters, {
find: {
$or: [
{title: {$regex: terms.query, $options: 'i'}},
{url: {$regex: terms.query, $options: 'i'}},
{body: {$regex: terms.query, $options: 'i'}}
]
}
});
return parameters;
}