Fix #4638: Add exclusions to the numeric attributes.
Add the following search operators: * /tags?search[post_count_eq]=42 * /tags?search[post_count_not_eq]=42 * /tags?search[post_count_gt]=42 * /tags?search[post_count_gteq]=42 * /tags?search[post_count_lt]=42 * /tags?search[post_count_lteq]=42 Works for all numeric attributes on all index actions.
This commit is contained in:
@@ -183,7 +183,7 @@ module Searchable
|
||||
when :boolean
|
||||
search_boolean_attribute(name, params)
|
||||
when :integer, :datetime
|
||||
numeric_attribute_matches(name, params[name])
|
||||
search_numeric_attribute(name, params)
|
||||
when :inet
|
||||
search_inet_attribute(name, params)
|
||||
when :enum
|
||||
@@ -196,6 +196,26 @@ module Searchable
|
||||
end
|
||||
end
|
||||
|
||||
def search_numeric_attribute(attr, params)
|
||||
if params[attr].present?
|
||||
numeric_attribute_matches(attr, params[attr])
|
||||
elsif params[:"#{attr}_eq"].present?
|
||||
where_operator(attr, :eq, params[:"#{attr}_eq"])
|
||||
elsif params[:"#{attr}_not_eq"].present?
|
||||
where_operator(attr, :not_eq, params[:"#{attr}_not_eq"])
|
||||
elsif params[:"#{attr}_gt"].present?
|
||||
where_operator(attr, :gt, params[:"#{attr}_gt"])
|
||||
elsif params[:"#{attr}_gteq"].present?
|
||||
where_operator(attr, :gteq, params[:"#{attr}_gteq"])
|
||||
elsif params[:"#{attr}_lt"].present?
|
||||
where_operator(attr, :lt, params[:"#{attr}_lt"])
|
||||
elsif params[:"#{attr}_lteq"].present?
|
||||
where_operator(attr, :lteq, params[:"#{attr}_lteq"])
|
||||
else
|
||||
all
|
||||
end
|
||||
end
|
||||
|
||||
def search_text_attribute(attr, params)
|
||||
if params[attr].present?
|
||||
where(attr => params[attr])
|
||||
|
||||
Reference in New Issue
Block a user