FEATURE: Change very high/low search priority to rank at absolute ends.

Prior to this change, we had weights for very_high, high, low and
very_low. This means there were 4 weights to tweak and what weights to
use for `very_high/high` and `very_low/low` pair was hard to explain.
This change makes it such that `very_high` search priority will always
ensure that the posts are ranked at the top while `very_low` search
priority will ensure that the posts are ranked at the very bottom.
This commit is contained in:
Alan Guo Xiang Tan
2020-12-23 15:14:41 +08:00
parent 082a77df69
commit ebe4896e48
7 changed files with 80 additions and 49 deletions

View File

@@ -1019,17 +1019,25 @@ class Search
)
SQL
category_search_priority = <<~SQL
(
CASE categories.search_priority
WHEN #{Searchable::PRIORITIES[:very_high]}
THEN 3
WHEN #{Searchable::PRIORITIES[:very_low]}
THEN 1
ELSE 2
END
)
SQL
category_priority_weights = <<~SQL
(
CASE categories.search_priority
WHEN #{Searchable::PRIORITIES[:very_low]}
THEN #{SiteSetting.category_search_priority_very_low_weight}
WHEN #{Searchable::PRIORITIES[:low]}
THEN #{SiteSetting.category_search_priority_low_weight}
WHEN #{Searchable::PRIORITIES[:high]}
THEN #{SiteSetting.category_search_priority_high_weight}
WHEN #{Searchable::PRIORITIES[:very_high]}
THEN #{SiteSetting.category_search_priority_very_high_weight}
ELSE
CASE WHEN topics.closed
THEN 0.9
@@ -1048,9 +1056,9 @@ class Search
posts =
if aggregate_search
posts.order("MAX(#{data_ranking}) DESC")
posts.order("MAX(#{category_search_priority}) DESC", "MAX(#{data_ranking}) DESC")
else
posts.order("#{data_ranking} DESC")
posts.order("#{category_search_priority} DESC", "#{data_ranking} DESC")
end
posts = posts.order("topics.bumped_at DESC")

View File

@@ -9,14 +9,10 @@ class CategorySearchPriorityWeightsValidator
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
val < 1
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
val > 1
end
end