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};
}
if (data.cid) {
searchQuery.cid = data.cid;
if (Array.isArray(data.cid) && data.cid.length) {
if (data.cid.length > 1) {
searchQuery.cid = {$in: data.cid.map(String)};
} else {
searchQuery.cid = data.cid[0].toString();
}
}
if (data.uid) {
searchQuery.uid = data.uid;
if (Array.isArray(data.uid) && data.uid.length) {
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) {

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

@ -335,7 +335,15 @@ var async = require('async'),
};
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) {

Loading…
Cancel
Save