reply count filter atleast/atmost

v1.18.x
barisusakli 10 years ago
parent a12bb9a32c
commit 161b934827

@ -5,5 +5,8 @@
"by": "By",
"posted-by": "Posted by",
"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) {
$('.by-container #posted-by-user').val(params.by);
$('#posted-by-user').val(params.by);
}
if (params && params['categories[]']) {
@ -27,8 +27,14 @@ define('forum/search', ['search'], function(searchModule) {
$('#search-children').prop('checked', true);
}
if (params && params.replies) {
$('#reply-count').val(params.replies);
$('#reply-count-filter').val(params.repliesFilter);
}
searchIn.on('change', function() {
$('.by-container').toggleClass('hide', searchIn.val() !== 'posts');
$('.post-search-item').toggleClass('hide', searchIn.val() !== 'posts');
});
highlightMatches(searchQuery);
@ -42,7 +48,9 @@ define('forum/search', ['search'], function(searchModule) {
in: $(this).find('#search-in').val(),
by: $(this).find('#posted-by-user').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() {
input.val('');
});
@ -71,7 +79,7 @@ define('forum/search', ['search'], function(searchModule) {
function enableAutoComplete() {
var input = $('.by-container #posted-by-user');
var input = $('#posted-by-user');
input.autocomplete({
delay: 100,
source: function(request, response) {

@ -34,6 +34,12 @@ define('search', ['navigator'], function(nav) {
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)));
callback();
} else {

@ -43,6 +43,8 @@ searchController.search = function(req, res, next) {
postedBy: req.query.by,
categories: req.query.categories,
searchChildren: req.query.searchChildren,
replies: req.query.replies,
repliesFilter: req.query.repliesFilter,
uid: uid
}, function(err, results) {
if (err) {

@ -50,7 +50,6 @@ search.search = function(data, callback) {
function searchInPosts(query, data, callback) {
data.uid = data.uid || 0;
var postedBy = data.postedBy || '';
async.parallel({
pids: function(next) {
searchQuery('post', query, next);
@ -86,20 +85,28 @@ function searchInPosts(query, data, callback) {
posts.getPostSummaryByPids(pids, data.uid, {stripTags: true, parse: false}, next);
},
function(posts, next) {
var searchCategories = results.searchCategories;
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);
});
}
posts = filterPosts(data, results.searchCategories, posts);
next(null, posts);
}
], 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) {
if (!Array.isArray(data.categories) || !data.categories.length || data.categories.indexOf('all') !== -1) {
return callback(null, []);

Loading…
Cancel
Save