diff --git a/src/search.js b/src/search.js index a0c156535a..a2bb96a33f 100644 --- a/src/search.js +++ b/src/search.js @@ -149,8 +149,8 @@ function filterAndSort(pids, data, callback) { } function getMatchedPosts(pids, data, callback) { - var postFields = ['pid', 'tid', 'timestamp']; - var topicFields = []; + var postFields = ['pid', 'tid', 'timestamp', 'deleted']; + var topicFields = ['deleted']; var categoryFields = []; if (data.replies) { @@ -180,7 +180,9 @@ function getMatchedPosts(pids, data, callback) { db.getObjectsFields(keys, postFields, next); }, function(_posts, next) { - posts = _posts; + posts = _posts.filter(function(post) { + return post && parseInt(post.deleted, 10) !== 1; + }); async.parallel({ users: function(next) { @@ -194,10 +196,6 @@ function getMatchedPosts(pids, data, callback) { } }, topics: function(next) { - if (!topicFields.length) { - return next(); - } - var topics; async.waterfall([ function(next) { @@ -268,6 +266,10 @@ function getMatchedPosts(pids, data, callback) { } }); + posts = posts.filter(function(post) { + return post && post.topic && parseInt(post.topic.deleted, 10) !== 1; + }); + next(null, posts); } ], callback);