Skip to content

A platform for community discussion. Free, open, simple.

PERF: Speed up post searches that match all text weights (#44314)

Alan Guo Xiang Tanadc9f2fe1d7a
diff --git a/lib/search.rb b/lib/search.rb
index d9880b29c19..58440fe99e5 100644
--- a/lib/search.rb
+++ b/lib/search.rb
@@ -1277,7 +1277,8 @@ class Search
posts = posts.where("#{user_search_fields} ILIKE ?", "%#{term_without_quote}%")
else
posts = posts.where(post_number: 1) if @in_title
- posts = posts.where("post_search_data.search_data @@ #{ts_query(weight_filter: weights)}")
+ weight_filter = weights == "ABCD" ? nil : weights
+ posts = posts.where("post_search_data.search_data @@ #{ts_query(weight_filter:)}")
exact_terms = @term.scan(Regexp.new(PHRASE_MATCH_REGEXP_PATTERN)).flatten
exact_terms.each do |exact|