mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-08 06:55:46 +01:00
closes #3002
This commit is contained in:
@@ -49,8 +49,7 @@ searchController.search = function(req, res, next) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
var pageCount = Math.max(1, Math.ceil(results.matchCount / 10));
|
||||
results.pagination = pagination.create(page, pageCount, req.query);
|
||||
results.pagination = pagination.create(page, results.pageCount, req.query);
|
||||
results.showAsPosts = !req.query.showAs || req.query.showAs === 'posts';
|
||||
results.showAsTopics = req.query.showAs === 'topics';
|
||||
results.breadcrumbs = breadcrumbs;
|
||||
|
||||
@@ -27,6 +27,7 @@ search.search = function(data, callback) {
|
||||
}
|
||||
result[searchIn] = data.matches;
|
||||
result.matchCount = data.matchCount;
|
||||
result.pageCount = data.pageCount;
|
||||
result.time = (process.elapsedTimeSince(start) / 1000).toFixed(2);
|
||||
callback(null, result);
|
||||
}
|
||||
@@ -45,7 +46,7 @@ search.search = function(data, callback) {
|
||||
if (searchIn === 'posts' || searchIn === 'titles' || searchIn === 'titlesposts') {
|
||||
searchInContent(data, done);
|
||||
} else if (searchIn === 'users') {
|
||||
searchInUsers(query, data.uid, done);
|
||||
searchInUsers(data, done);
|
||||
} else if (searchIn === 'tags') {
|
||||
searchInTags(query, done);
|
||||
} else {
|
||||
@@ -89,7 +90,7 @@ function searchInContent(data, callback) {
|
||||
|
||||
var matchCount = 0;
|
||||
if (!results || (!results.pids.length && !results.tids.length)) {
|
||||
return callback(null, {matches: [], matchCount: matchCount});
|
||||
return callback(null, {matches: [], matchCount: matchCount, pageCount: 1});
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
@@ -116,7 +117,7 @@ function searchInContent(data, callback) {
|
||||
posts.getPostSummaryByPids(pids, data.uid, {stripTags: true, parse: false}, next);
|
||||
},
|
||||
function(posts, next) {
|
||||
next(null, {matches: posts, matchCount: matchCount});
|
||||
next(null, {matches: posts, matchCount: matchCount, pageCount: Math.max(1, Math.ceil(parseInt(matchCount, 10) / 10))});
|
||||
}
|
||||
], callback);
|
||||
});
|
||||
@@ -432,12 +433,12 @@ function getSearchUids(data, callback) {
|
||||
}
|
||||
}
|
||||
|
||||
function searchInUsers(query, uid, callback) {
|
||||
user.search({query: query, uid: uid}, function(err, results) {
|
||||
function searchInUsers(data, callback) {
|
||||
user.search(data, function(err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
callback(null, {matches: results.users, matchCount: results.matchCount});
|
||||
callback(null, {matches: results.users, matchCount: results.matchCount, pageCount: results.pageCount});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -447,7 +448,7 @@ function searchInTags(query, callback) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
callback(null, {matches: tags, matchCount: tags.length});
|
||||
callback(null, {matches: tags, matchCount: tags.length, pageCount: 1});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ module.exports = function(User) {
|
||||
var pagination = user.paginate(page, uids);
|
||||
uids = pagination.data;
|
||||
searchResult.pagination = pagination.pagination;
|
||||
searchResult.pageCount = pagination.pageCount;
|
||||
}
|
||||
|
||||
User.getUsers(uids, uid, next);
|
||||
@@ -66,6 +67,7 @@ module.exports = function(User) {
|
||||
|
||||
return {
|
||||
pagination: pagination.create(currentPage, pageCount),
|
||||
pageCount: pageCount,
|
||||
data: data.slice(start, stop)
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user