Implementation tries to be open for further extensions, such as deciding on search dictionary based on configuration option or by locale set for given user.
23 lines
643 B
Ruby
23 lines
643 B
Ruby
module Searchable
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
include PgSearch
|
|
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
|