Node.js based forum software built for the modern web
part 2 of search changes
barisusaklie2196af8ab38
diff --git a/src/database/mongo/main.js b/src/database/mongo/main.jsindex a40567e2a6..6302d76fb2 100644--- a/src/database/mongo/main.js+++ b/src/database/mongo/main.js@@ -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) {diff --git a/src/database/redis/main.js b/src/database/redis/main.jsindex 9ed956f0b3..b09574e10f 100644--- a/src/database/redis/main.js+++ b/src/database/redis/main.js@@ -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) {diff --git a/src/search.js b/src/search.jsindex a478d7f8e9..8315312bec 100644--- a/src/search.js+++ b/src/search.js@@ -104,7 +104,7 @@ console.log(results)privileges.posts.filter('read', results.pids, data.uid, next);},function(pids, next) {- filterAndSort(pids, data, results.searchCategories, next);+ filterAndSort(pids, data, next);},function(pids, next) {matchCount = pids.length;@@ -124,18 +124,15 @@ console.log(results)}function filterAndSort(pids, data, callback) {- async.parallel({- posts: function(next) {- getMatchedPosts(pids, data, next);- }- }, function(err, results) {+ getMatchedPosts(pids, data, function(err, posts) {if (err) {return callback(err);}- if (!results.posts) {++ if (!Array.isArray(posts) || !posts.length) {return callback(null, pids);}- var posts = results.posts.filter(Boolean);+ posts = posts.filter(Boolean);posts = filterByPostcount(posts, data.replies, data.repliesFilter);posts = filterByTimerange(posts, data.timeRange, data.timeFilter);@@ -155,20 +152,14 @@ function getMatchedPosts(pids, data, callback) {var topicFields = [];var categoryFields = [];- if (data.postedBy) {- postFields.push('uid');- }-- if (data.sortBy && data.sortBy.startsWith('category.')) {- topicFields.push('cid');- }-if (data.replies) {topicFields.push('postcount');}if (data.sortBy) {- if (data.sortBy.startsWith('topic.')) {+ if (data.sortBy.startsWith('category')) {+ topicFields.push('cid');+ } else if (data.sortBy.startsWith('topic.')) {topicFields.push(data.sortBy.split('.')[1]);} else if (data.sortBy.startsWith('user.')) {postFields.push('uid');@@ -281,25 +272,6 @@ function getMatchedPosts(pids, data, callback) {], callback);}-function filterByUser(posts, postedByUid) {- if (postedByUid) {- postedByUid = parseInt(postedByUid, 10);- posts = posts.filter(function(post) {- return parseInt(post.uid, 10) === postedByUid;- });- }- return posts;-}--function filterByCategories(posts, searchCategories) {- if (searchCategories.length) {- posts = posts.filter(function(post) {- return post.topic && searchCategories.indexOf(post.topic.cid) !== -1;- });- }- return posts;-}-function filterByPostcount(posts, postCount, repliesFilter) {postCount = parseInt(postCount, 10);if (postCount) {@@ -475,8 +447,8 @@ search.searchQuery = function(index, content, cids, uids, callback) {plugins.fireHook('filter:search.query', {index: index,content: content,- cids: cids,- uids: uids+ cid: cids,+ uid: uids}, callback);};