mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Support posts-min:<count> and posts-max:<count> on /filter (#21090)
This commit adds support for the `posts-min:<count>` and `posts-max:<count>` filters for the topics filtering query language. `posts-min:1` will filter for topics with at least a one post while `posts-max:3` will filter foor topics with a maximum of 3 posts. If the filter has an invalid value, i.e string that cannot be converted into an integer, the filter will be ignored. If either of each filter is specify multiple times, only the last occurence of each filter will be taken into consideration.
This commit is contained in:
committed by
GitHub
parent
9b3408223b
commit
bc4a9c50f2
@@ -40,6 +40,10 @@ class TopicsFilter
|
||||
filter_created_by_user(usernames: values.flat_map { |value| value.split(",") })
|
||||
when "in"
|
||||
filter_in(values: values)
|
||||
when "posts-min"
|
||||
filter_by_number_of_posts(min: values.last)
|
||||
when "posts-max"
|
||||
filter_by_number_of_posts(max: values.last)
|
||||
when "status"
|
||||
values.each { |status| @scope = filter_status(status: status) }
|
||||
when "tags"
|
||||
@@ -77,6 +81,13 @@ class TopicsFilter
|
||||
|
||||
private
|
||||
|
||||
def filter_by_number_of_posts(min: nil, max: nil)
|
||||
{ min => ">=", max => "<=" }.each do |value, operator|
|
||||
next if !value || value !~ /^\d+$/
|
||||
@scope = @scope.where("topics.posts_count #{operator} ?", value)
|
||||
end
|
||||
end
|
||||
|
||||
def filter_categories(values:)
|
||||
exclude_subcategories_category_slugs = []
|
||||
include_subcategories_category_slugs = []
|
||||
|
||||
Reference in New Issue
Block a user