mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-08 06:55:46 +01:00
reply count filter atleast/atmost
This commit is contained in:
@@ -5,5 +5,8 @@
|
|||||||
"by": "By",
|
"by": "By",
|
||||||
"posted-by": "Posted by",
|
"posted-by": "Posted by",
|
||||||
"in-categories": "In Categories",
|
"in-categories": "In Categories",
|
||||||
"search-child-categories": "Search child categories"
|
"search-child-categories": "Search child categories",
|
||||||
|
"reply-count": "Reply Count",
|
||||||
|
"at-least": "At least",
|
||||||
|
"at-most": "At most"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ define('forum/search', ['search'], function(searchModule) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (params && params.by) {
|
if (params && params.by) {
|
||||||
$('.by-container #posted-by-user').val(params.by);
|
$('#posted-by-user').val(params.by);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params && params['categories[]']) {
|
if (params && params['categories[]']) {
|
||||||
@@ -27,8 +27,14 @@ define('forum/search', ['search'], function(searchModule) {
|
|||||||
$('#search-children').prop('checked', true);
|
$('#search-children').prop('checked', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (params && params.replies) {
|
||||||
|
$('#reply-count').val(params.replies);
|
||||||
|
$('#reply-count-filter').val(params.repliesFilter);
|
||||||
|
}
|
||||||
|
|
||||||
searchIn.on('change', function() {
|
searchIn.on('change', function() {
|
||||||
$('.by-container').toggleClass('hide', searchIn.val() !== 'posts');
|
$('.post-search-item').toggleClass('hide', searchIn.val() !== 'posts');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
highlightMatches(searchQuery);
|
highlightMatches(searchQuery);
|
||||||
@@ -42,7 +48,9 @@ define('forum/search', ['search'], function(searchModule) {
|
|||||||
in: $(this).find('#search-in').val(),
|
in: $(this).find('#search-in').val(),
|
||||||
by: $(this).find('#posted-by-user').val(),
|
by: $(this).find('#posted-by-user').val(),
|
||||||
categories: $(this).find('#posted-in-categories').val(),
|
categories: $(this).find('#posted-in-categories').val(),
|
||||||
searchChildren: $(this).find('#search-children').is(':checked')
|
searchChildren: $(this).find('#search-children').is(':checked'),
|
||||||
|
replies: $(this).find('#reply-count').val(),
|
||||||
|
repliesFilter: $(this).find('#reply-count-filter').val()
|
||||||
}, function() {
|
}, function() {
|
||||||
input.val('');
|
input.val('');
|
||||||
});
|
});
|
||||||
@@ -71,7 +79,7 @@ define('forum/search', ['search'], function(searchModule) {
|
|||||||
|
|
||||||
|
|
||||||
function enableAutoComplete() {
|
function enableAutoComplete() {
|
||||||
var input = $('.by-container #posted-by-user');
|
var input = $('#posted-by-user');
|
||||||
input.autocomplete({
|
input.autocomplete({
|
||||||
delay: 100,
|
delay: 100,
|
||||||
source: function(request, response) {
|
source: function(request, response) {
|
||||||
|
|||||||
@@ -34,6 +34,12 @@ define('search', ['navigator'], function(nav) {
|
|||||||
query.searchChildren = data.searchChildren;
|
query.searchChildren = data.searchChildren;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (parseInt(data.replies, 10) > 0) {
|
||||||
|
query.replies = data.replies;
|
||||||
|
query.repliesFilter = data.repliesFilter || 'atleast';
|
||||||
|
}
|
||||||
|
|
||||||
ajaxify.go('search/' + term + '?' + decodeURIComponent($.param(query)));
|
ajaxify.go('search/' + term + '?' + decodeURIComponent($.param(query)));
|
||||||
callback();
|
callback();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ searchController.search = function(req, res, next) {
|
|||||||
postedBy: req.query.by,
|
postedBy: req.query.by,
|
||||||
categories: req.query.categories,
|
categories: req.query.categories,
|
||||||
searchChildren: req.query.searchChildren,
|
searchChildren: req.query.searchChildren,
|
||||||
|
replies: req.query.replies,
|
||||||
|
repliesFilter: req.query.repliesFilter,
|
||||||
uid: uid
|
uid: uid
|
||||||
}, function(err, results) {
|
}, function(err, results) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ search.search = function(data, callback) {
|
|||||||
|
|
||||||
function searchInPosts(query, data, callback) {
|
function searchInPosts(query, data, callback) {
|
||||||
data.uid = data.uid || 0;
|
data.uid = data.uid || 0;
|
||||||
var postedBy = data.postedBy || '';
|
|
||||||
async.parallel({
|
async.parallel({
|
||||||
pids: function(next) {
|
pids: function(next) {
|
||||||
searchQuery('post', query, next);
|
searchQuery('post', query, next);
|
||||||
@@ -86,20 +85,28 @@ function searchInPosts(query, 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) {
|
||||||
var searchCategories = results.searchCategories;
|
posts = filterPosts(data, results.searchCategories, posts);
|
||||||
if (postedBy || searchCategories.length) {
|
|
||||||
posts = posts.filter(function(post) {
|
|
||||||
return post &&
|
|
||||||
(postedBy ? post.user.username === postedBy : true) &&
|
|
||||||
(searchCategories.length ? searchCategories.indexOf(post.category.cid) !== -1 : true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
next(null, posts);
|
next(null, posts);
|
||||||
}
|
}
|
||||||
], callback);
|
], callback);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function filterPosts(data, searchCategories, posts) {
|
||||||
|
var postedBy = data.postedBy;
|
||||||
|
var isAtLeast = data.repliesFilter === 'atleast';
|
||||||
|
data.replies = parseInt(data.replies, 10);
|
||||||
|
if (postedBy || searchCategories.length || data.replies) {
|
||||||
|
posts = posts.filter(function(post) {
|
||||||
|
return post &&
|
||||||
|
(postedBy ? post.user.username === postedBy : true) &&
|
||||||
|
(searchCategories.length ? searchCategories.indexOf(post.category.cid) !== -1 : true) &&
|
||||||
|
(data.replies ? (isAtLeast ? post.topic.postcount >= data.replies : post.topic.postcount <= data.replies) : true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return posts;
|
||||||
|
}
|
||||||
|
|
||||||
function getSearchCategories(data, callback) {
|
function getSearchCategories(data, callback) {
|
||||||
if (!Array.isArray(data.categories) || !data.categories.length || data.categories.indexOf('all') !== -1) {
|
if (!Array.isArray(data.categories) || !data.categories.length || data.categories.indexOf('all') !== -1) {
|
||||||
return callback(null, []);
|
return callback(null, []);
|
||||||
|
|||||||
Reference in New Issue
Block a user