FEATURE: Allow categories to be prioritized/deprioritized in search. (#7209)

This commit is contained in:
Guo Xiang Tan
2019-03-25 10:59:55 +08:00
committed by GitHub
parent ce75e30bf5
commit ac661e856a
10 changed files with 129 additions and 5 deletions

View File

@ -0,0 +1,25 @@
class CategorySearchPriorityWeightsValidator
def initialize(opts = {})
@name = opts[:name].to_s
end
def valid_value?(val)
val = val.to_f
case @name
when "category_search_priority_very_low_weight"
val < SiteSetting.category_search_priority_low_weight
when "category_search_priority_low_weight"
val < 1 && val > SiteSetting.category_search_priority_very_low_weight
when "category_search_priority_high_weight"
val > 1 && val < SiteSetting.category_search_priority_very_high_weight
when "category_search_priority_very_high_weight"
val > SiteSetting.category_search_priority_high_weight
end
end
def error_message
key = @name[/category_search_priority_(\w+)_weight/, 1]
I18n.t("site_settings.errors.category_search_priority.#{key}_weight_invalid")
end
end