mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
limit search in db
This commit is contained in:
@@ -124,9 +124,8 @@
|
||||
});
|
||||
}
|
||||
|
||||
module.search = function(key, term, callback) {
|
||||
|
||||
db.command({text:"search" , search: term, filter: {key:key} }, function(err, result) {
|
||||
module.search = function(key, term, limit, callback) {
|
||||
db.command({text:"search" , search: term, filter: {key:key}, limit: limit }, function(err, result) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
@@ -97,10 +97,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
module.search = function(key, term, callback) {
|
||||
module.search = function(key, term, limit, callback) {
|
||||
function search(searchObj, callback) {
|
||||
searchObj
|
||||
.query(term).type('or')
|
||||
.query(term)
|
||||
.between(0, limit - 1)
|
||||
.type('or')
|
||||
.end(callback);
|
||||
}
|
||||
|
||||
|
||||
@@ -251,17 +251,14 @@ var path = require('path'),
|
||||
});
|
||||
|
||||
app.get('/search/:term', function (req, res, next) {
|
||||
var limit = 50;
|
||||
|
||||
function searchPosts(callback) {
|
||||
db.search('post', req.params.term, function(err, pids) {
|
||||
db.search('post', req.params.term, limit, function(err, pids) {
|
||||
if (err) {
|
||||
return callback(err, null);
|
||||
}
|
||||
|
||||
if(pids.length > 50) {
|
||||
pids = pids.splice(0, 50);
|
||||
}
|
||||
|
||||
posts.getPostSummaryByPids(pids, false, function (err, posts) {
|
||||
if (err){
|
||||
return callback(err, null);
|
||||
@@ -272,15 +269,11 @@ var path = require('path'),
|
||||
}
|
||||
|
||||
function searchTopics(callback) {
|
||||
db.search('topic', req.params.term, function(err, tids) {
|
||||
db.search('topic', req.params.term, limit, function(err, tids) {
|
||||
if (err) {
|
||||
return callback(err, null);
|
||||
}
|
||||
|
||||
if(tids.length > 50) {
|
||||
tids = tids.splice(0, 50);
|
||||
}
|
||||
|
||||
topics.getTopicsByTids(tids, 0, function (topics) {
|
||||
callback(null, topics);
|
||||
}, 0);
|
||||
@@ -290,7 +283,7 @@ var path = require('path'),
|
||||
if ((req.user && req.user.uid) || meta.config.allowGuestSearching === '1') {
|
||||
async.parallel([searchPosts, searchTopics], function (err, results) {
|
||||
if (err) {
|
||||
return next();
|
||||
return next(err);
|
||||
}
|
||||
|
||||
return res.json({
|
||||
|
||||
@@ -28,6 +28,7 @@ var users = {},
|
||||
io;
|
||||
|
||||
Sockets.init = function() {
|
||||
|
||||
io = socketioWildcard(SocketIO).listen(global.server, {
|
||||
log: false,
|
||||
transports: ['websocket', 'xhr-polling', 'jsonp-polling', 'flashsocket'],
|
||||
|
||||
@@ -493,11 +493,12 @@ var bcrypt = require('bcrypt'),
|
||||
return callback([]);
|
||||
}
|
||||
|
||||
db.search('user', username, function(err, uids) {
|
||||
db.search('user', username, 50, function(err, uids) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (uids && uids.length) {
|
||||
User.getDataForUsers(uids, function(userdata) {
|
||||
callback(userdata);
|
||||
|
||||
Reference in New Issue
Block a user