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);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
var pageCount = Math.max(1, Math.ceil(results.matchCount / 10));
|
results.pagination = pagination.create(page, results.pageCount, req.query);
|
||||||
results.pagination = pagination.create(page, pageCount, req.query);
|
|
||||||
results.showAsPosts = !req.query.showAs || req.query.showAs === 'posts';
|
results.showAsPosts = !req.query.showAs || req.query.showAs === 'posts';
|
||||||
results.showAsTopics = req.query.showAs === 'topics';
|
results.showAsTopics = req.query.showAs === 'topics';
|
||||||
results.breadcrumbs = breadcrumbs;
|
results.breadcrumbs = breadcrumbs;
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ search.search = function(data, callback) {
|
|||||||
}
|
}
|
||||||
result[searchIn] = data.matches;
|
result[searchIn] = data.matches;
|
||||||
result.matchCount = data.matchCount;
|
result.matchCount = data.matchCount;
|
||||||
|
result.pageCount = data.pageCount;
|
||||||
result.time = (process.elapsedTimeSince(start) / 1000).toFixed(2);
|
result.time = (process.elapsedTimeSince(start) / 1000).toFixed(2);
|
||||||
callback(null, result);
|
callback(null, result);
|
||||||
}
|
}
|
||||||
@@ -45,7 +46,7 @@ search.search = function(data, callback) {
|
|||||||
if (searchIn === 'posts' || searchIn === 'titles' || searchIn === 'titlesposts') {
|
if (searchIn === 'posts' || searchIn === 'titles' || searchIn === 'titlesposts') {
|
||||||
searchInContent(data, done);
|
searchInContent(data, done);
|
||||||
} else if (searchIn === 'users') {
|
} else if (searchIn === 'users') {
|
||||||
searchInUsers(query, data.uid, done);
|
searchInUsers(data, done);
|
||||||
} else if (searchIn === 'tags') {
|
} else if (searchIn === 'tags') {
|
||||||
searchInTags(query, done);
|
searchInTags(query, done);
|
||||||
} else {
|
} else {
|
||||||
@@ -89,7 +90,7 @@ function searchInContent(data, callback) {
|
|||||||
|
|
||||||
var matchCount = 0;
|
var matchCount = 0;
|
||||||
if (!results || (!results.pids.length && !results.tids.length)) {
|
if (!results || (!results.pids.length && !results.tids.length)) {
|
||||||
return callback(null, {matches: [], matchCount: matchCount});
|
return callback(null, {matches: [], matchCount: matchCount, pageCount: 1});
|
||||||
}
|
}
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
@@ -116,7 +117,7 @@ function searchInContent(data, callback) {
|
|||||||
posts.getPostSummaryByPids(pids, data.uid, {stripTags: true, parse: false}, next);
|
posts.getPostSummaryByPids(pids, data.uid, {stripTags: true, parse: false}, next);
|
||||||
},
|
},
|
||||||
function(posts, 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);
|
], callback);
|
||||||
});
|
});
|
||||||
@@ -432,12 +433,12 @@ function getSearchUids(data, callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function searchInUsers(query, uid, callback) {
|
function searchInUsers(data, callback) {
|
||||||
user.search({query: query, uid: uid}, function(err, results) {
|
user.search(data, function(err, results) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(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);
|
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);
|
var pagination = user.paginate(page, uids);
|
||||||
uids = pagination.data;
|
uids = pagination.data;
|
||||||
searchResult.pagination = pagination.pagination;
|
searchResult.pagination = pagination.pagination;
|
||||||
|
searchResult.pageCount = pagination.pageCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
User.getUsers(uids, uid, next);
|
User.getUsers(uids, uid, next);
|
||||||
@@ -66,6 +67,7 @@ module.exports = function(User) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
pagination: pagination.create(currentPage, pageCount),
|
pagination: pagination.create(currentPage, pageCount),
|
||||||
|
pageCount: pageCount,
|
||||||
data: data.slice(start, stop)
|
data: data.slice(start, stop)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user