mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 14:35:47 +01:00
search filters
This commit is contained in:
41
src/controllers/search.js
Normal file
41
src/controllers/search.js
Normal file
@@ -0,0 +1,41 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var searchController = {},
|
||||
validator = require('validator'),
|
||||
plugins = require('../plugins'),
|
||||
search = require('../search'),
|
||||
helpers = require('./helpers');
|
||||
|
||||
|
||||
searchController.search = function(req, res, next) {
|
||||
if (!plugins.hasListeners('filter:search.query')) {
|
||||
return helpers.notFound(req, res);
|
||||
}
|
||||
|
||||
if (!req.params.term) {
|
||||
return res.render('search', {
|
||||
time: 0,
|
||||
search_query: '',
|
||||
posts: [],
|
||||
topics: [],
|
||||
users: [],
|
||||
tags: []
|
||||
});
|
||||
}
|
||||
|
||||
var uid = req.user ? req.user.uid : 0;
|
||||
|
||||
req.params.term = validator.escape(req.params.term);
|
||||
|
||||
search.search(req.params.term, req.query.in, uid, function(err, results) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.render('search', results);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
module.exports = searchController;
|
||||
Reference in New Issue
Block a user