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