Skip to content

Node.js based forum software built for the modern web

use topic.getMainPids

Barış Soner Uşaklıabf27954d378
diff --git a/src/search.js b/src/search.js
index 8ccdf77d78..e44dedc216 100644
--- a/src/search.js
+++ b/src/search.js
@@ -85,16 +85,14 @@ function searchInContent(query, data, callback) {
async.waterfall([
function(next) {
- getMainPids(results.tids, next);
+ topics.getMainPids(results.tids, next);
},
function(mainPids, next) {
- results.pids.forEach(function(pid) {
- if (mainPids.indexOf(pid.toString()) === -1) {
- mainPids.push(pid);
- }
+ results.pids = mainPids.concat(results.pids).filter(function(pid, index, array) {
+ return pid && array.indexOf(pid) === index;
});
-
- privileges.posts.filter('read', mainPids, data.uid, next);
+
+ privileges.posts.filter('read', results.pids, data.uid, next);
},
function(pids, next) {
filterAndSort(pids, data, results.searchCategories, next);
@@ -460,22 +458,6 @@ function searchInTags(query, callback) {
});
}
-function getMainPids(tids, callback) {
- if (!Array.isArray(tids) || !tids.length) {
- return callback(null, []);
- }
-
- topics.getTopicsFields(tids, ['mainPid'], function(err, topics) {
- if (err) {
- return callback(err);
- }
- topics = topics.map(function(topic) {
- return topic && topic.mainPid && topic.mainPid.toString();
- }).filter(Boolean);
- callback(null, topics);
- });
-}
-
search.searchQuery = function(index, query, callback) {
plugins.fireHook('filter:search.query', {
index: index,
diff --git a/src/topics.js b/src/topics.js
index aecdcb1000..0cc153e85e 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -287,13 +287,17 @@ var async = require('async'),
};
Topics.getMainPids = function(tids, callback) {
+ if (!Array.isArray(tids) || !tids.length) {
+ return callback(null, []);
+ }
+
Topics.getTopicsFields(tids, ['mainPid'], function(err, topicData) {
if (err) {
return callback(err);
}
var mainPids = topicData.map(function(topic) {
- return topic ? topic.mainPid : null;
+ return topic && topic.mainPid;
});
callback(null, mainPids);
});