Using pg_search 2.0.1 with Rails 5.2 results in deprecation warnings: DEPRECATION WARNING: Dangerous query method (method whose arguments used as raw SQL) called with non-attribute argument(s): "pg_search_978c2f8941354cf552831b.rank DESC, \"tags\".\"id\" ASC". Non-attribute arguments will be disallowed in Rails 6.0. This method should not be called with user-provided values, such as request parameters or model attributes. Known-safe values can be passed by wrapping them in Arel.sql(). We're not upgrading to the latest pg_search because it only supports ActiveRecord >= 5.2.
23 lines
650 B
Ruby
23 lines
650 B
Ruby
module Searchable
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
include PgSearch::Model
|
|
include SearchCache
|
|
|
|
pg_search_scope :pg_search, ->(query) do
|
|
cached_votes_up_present = column_names.include?("cached_votes_up")
|
|
{
|
|
against: :ignored, # not used since using a tsvector_column
|
|
using: {
|
|
tsearch: { tsvector_column: "tsv", dictionary: SearchDictionarySelector.call, prefix: true }
|
|
},
|
|
ignoring: :accents,
|
|
ranked_by: "(:tsearch)",
|
|
order_within_rank: (cached_votes_up_present ? "#{table_name}.cached_votes_up DESC" : nil),
|
|
query: query
|
|
}
|
|
end
|
|
end
|
|
end
|