fix search on mongo

v1.18.x
barisusakli 10 years ago
parent 78c65aee05
commit ec7caea368

@ -34,12 +34,20 @@ module.exports = function(db, module) {
searchQuery.$text = {$search: data.content}; searchQuery.$text = {$search: data.content};
} }
if (data.cid) { if (Array.isArray(data.cid) && data.cid.length) {
searchQuery.cid = data.cid; if (data.cid.length > 1) {
searchQuery.cid = {$in: data.cid.map(String)};
} else {
searchQuery.cid = data.cid[0].toString();
}
} }
if (data.uid) { if (Array.isArray(data.uid) && data.uid.length) {
searchQuery.uid = data.uid; if (data.uid.length > 1) {
searchQuery.uid = {$in: data.uid.map(String)};
} else {
searchQuery.uid = data.uid[0].toString();
}
} }
db.collection('search').find(searchQuery, {limit: limit}).toArray(function(err, results) { db.collection('search').find(searchQuery, {limit: limit}).toArray(function(err, results) {

@ -414,11 +414,7 @@ function getChildrenCids(cids, uid, callback) {
function getSearchUids(data, callback) { function getSearchUids(data, callback) {
if (data.postedBy) { if (data.postedBy) {
if (Array.isArray(data.postedBy)) { user.getUidsByUsernames(Array.isArray(data.postedBy) ? data.postedBy : [data.postedBy], callback);
user.getUidsByUsernames(data.postedBy, callback);
} else {
user.getUidByUsername([data.postedBy], callback);
}
} else { } else {
callback(null, []); callback(null, []);
} }

@ -335,7 +335,15 @@ var async = require('async'),
}; };
User.getUidsByUsernames = function(usernames, callback) { User.getUidsByUsernames = function(usernames, callback) {
db.getObjectFields('username:uid', usernames, callback); db.getObjectFields('username:uid', usernames, function(err, users) {
if (err) {
return callback(err);
}
var uids = usernames.map(function(username) {
return users[username];
});
callback(null, uids);
});
}; };
User.getUidByUserslug = function(userslug, callback) { User.getUidByUserslug = function(userslug, callback) {

Loading…
Cancel
Save