part 2 of search changes

This commit is contained in:
barisusakli
2015-03-15 00:12:52 -04:00
parent c7128bcc98
commit e2196af8ab
3 changed files with 25 additions and 54 deletions

View File

@@ -64,7 +64,9 @@ module.exports = function(db, module) {
if (!id) {
return callback();
}
db.collection('search').remove({key: key, id: id}, callback);
db.collection('search').remove({key: key, id: id}, function(err, res) {
callback(err);
});
};
module.flushdb = function(callback) {

View File

@@ -2,19 +2,17 @@
module.exports = function(redisClient, module) {
module.searchIndex = function(key, data, id, callback) {
if (key === 'post') {
module.postSearch.index(data, id, callback);
} else if(key === 'topic') {
module.topicSearch.index(data, id, callback);
}
var method = key === 'post' ? module.postSearch : module.topicSearch;
method.index(data, id, function(err, res) {
callback(err);
});
};
module.search = function(key, data, limit, callback) {
if (key === 'post') {
module.postSearch.query(data, 0, limit - 1, callback);
} else if(key === 'topic') {
module.topicSearch.query(data, 0, limit - 1, callback);
}
var method = key === 'post' ? module.postSearch : module.topicSearch;
method.query(data, 0, limit - 1, callback);
};
module.searchRemove = function(key, id, callback) {
@@ -22,12 +20,11 @@ module.exports = function(redisClient, module) {
if (!id) {
return callback();
}
var method = key === 'post' ? module.postSearch : module.topicSearch;
if (key === 'post') {
module.postSearch.remove(id, callback);
} else if(key === 'topic') {
module.topicSearch.remove(id, callback);
}
method.remove(id, function(err, res) {
callback(err);
});
};
module.flushdb = function(callback) {