Commit 4c0bdaadcbeebf12041e99227c774dcd9afa9ccc
1 parent
a85eeffd
Exists in
theme-brasil-digital-from-staging
and in
6 other branches
pg_search: refactor search query
Showing
1 changed file
with
2 additions
and
3 deletions
Show diff stats
plugins/pg_search/lib/ext/active_record.rb
@@ -4,9 +4,8 @@ class ActiveRecord::Base | @@ -4,9 +4,8 @@ class ActiveRecord::Base | ||
4 | def self.pg_search_plugin_search(query) | 4 | def self.pg_search_plugin_search(query) |
5 | filtered_query = query.gsub(/[\|\(\)\\\/\s\[\]'"*%&!:]/,' ').split.map{|w| w += ":*"}.join('|') | 5 | filtered_query = query.gsub(/[\|\(\)\\\/\s\[\]'"*%&!:]/,' ').split.map{|w| w += ":*"}.join('|') |
6 | if defined?(self::SEARCHABLE_FIELDS) | 6 | if defined?(self::SEARCHABLE_FIELDS) |
7 | - select("*,ts_rank(to_tsvector('simple', #{pg_search_plugin_fields}), to_tsquery('#{filtered_query}')) as rank"). | ||
8 | - where("to_tsvector('simple', #{pg_search_plugin_fields}) @@ to_tsquery('#{filtered_query}')"). | ||
9 | - order("rank DESC") | 7 | + where("to_tsvector('simple', #{pg_search_plugin_fields}) @@ to_tsquery('#{filtered_query}')"). |
8 | + order("ts_rank(to_tsvector('simple', #{pg_search_plugin_fields}), to_tsquery('#{filtered_query}')) DESC") | ||
10 | else | 9 | else |
11 | raise "No searchable fields defined for #{self.name}" | 10 | raise "No searchable fields defined for #{self.name}" |
12 | end | 11 | end |