group searching

This commit is contained in:
Julian Lam
2015-01-21 15:43:05 -05:00
parent fa27461abc
commit 6502dd2561
3 changed files with 54 additions and 1 deletions

View File

@@ -898,4 +898,23 @@ var async = require('async'),
db.setRemove('group:' + groupName + ':owners', toUid, callback);
};
Groups.search = function(query, options, callback) {
if (!query || !query.length) {
return callback(null, []);
}
async.waterfall([
async.apply(db.getObjectValues, 'groupslug:groupname'),
function(groupNames, next) {
groupNames = groupNames.filter(function(name) {
return name.match(new RegExp(query, 'i'));
});
async.mapLimit(groupNames, 5, function(groupName, next) {
Groups.get(groupName, options || {}, next);
}, next);
}
], callback);
};
}(module.exports));