mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
fix search on mongo
This commit is contained in:
@@ -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, []);
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/user.js
10
src/user.js
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user