Files
nairobi/app/models/concerns/searchable.rb
Paweł Świątkowski d99875cde2 Get search dictionary based on I18n.default_locale (merge pull request #3856)
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.
2020-04-12 14:22:36 +02:00

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