barisusakli 9 years ago
parent 414762d382
commit 2fd121dc15

@ -241,8 +241,8 @@ var utils = require('../public/src/utils');
if (group) { if (group) {
group.nameEncoded = encodeURIComponent(group.name); group.nameEncoded = encodeURIComponent(group.name);
group.displayName = validator.escape(group.name); group.displayName = validator.escape(group.name);
group.description = validator.escape(group.description); group.description = validator.escape(group.description || '');
group.userTitle = validator.escape(group.userTitle) || group.displayName; group.userTitle = validator.escape(group.userTitle || '') || group.displayName;
} }
}; };

@ -1,45 +1,44 @@
'use strict'; 'use strict';
var async = require('async'), var async = require('async');
validator = require('validator'), var validator = require('validator');
db = require('./database'), var db = require('./database');
posts = require('./posts'), var posts = require('./posts');
topics = require('./topics'), var topics = require('./topics');
categories = require('./categories'), var categories = require('./categories');
user = require('./user'), var user = require('./user');
plugins = require('./plugins'), var plugins = require('./plugins');
privileges = require('./privileges'), var privileges = require('./privileges');
utils = require('../public/src/utils'); var utils = require('../public/src/utils');
var search = {}; var search = {};
module.exports = search; module.exports = search;
search.search = function(data, callback) { search.search = function(data, callback) {
function done(err, result) {
if (err) {
return callback(err);
}
result.search_query = validator.escape(data.query);
result.time = (process.elapsedTimeSince(start) / 1000).toFixed(2);
callback(null, result);
}
var start = process.hrtime(); var start = process.hrtime();
var searchIn = data.searchIn || 'titlesposts'; var searchIn = data.searchIn || 'titlesposts';
async.waterfall([
function (next) {
if (searchIn === 'posts' || searchIn === 'titles' || searchIn === 'titlesposts') { if (searchIn === 'posts' || searchIn === 'titles' || searchIn === 'titlesposts') {
searchInContent(data, done); searchInContent(data, next);
} else if (searchIn === 'users') { } else if (searchIn === 'users') {
user.search(data, done); user.search(data, next);
} else if (searchIn === 'tags') { } else if (searchIn === 'tags') {
topics.searchAndLoadTags(data, done); topics.searchAndLoadTags(data, next);
} else { } else {
callback(new Error('[[error:unknown-search-filter]]')); next(new Error('[[error:unknown-search-filter]]'));
}
},
function (result, next) {
result.search_query = validator.escape(data.query || '');
result.time = (process.elapsedTimeSince(start) / 1000).toFixed(2);
next(null, result);
} }
], callback);
}; };
function searchInContent(data, callback) { function searchInContent(data, callback) {

Loading…
Cancel
Save