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.
This commit is contained in:
committed by
GitHub
parent
426c1c5fd2
commit
d99875cde2
@@ -19,7 +19,8 @@ module SearchCache
|
||||
end
|
||||
|
||||
def set_tsvector(value, weight)
|
||||
"setweight(to_tsvector('spanish', unaccent(coalesce(#{quote(strip_html(value))}, ''))), #{quote(weight)})"
|
||||
dict = quote(SearchDictionarySelector.call)
|
||||
"setweight(to_tsvector(#{dict}, unaccent(coalesce(#{quote(strip_html(value))}, ''))), #{quote(weight)})"
|
||||
end
|
||||
|
||||
def quote(value)
|
||||
|
||||
@@ -5,14 +5,18 @@ module Searchable
|
||||
include PgSearch
|
||||
include SearchCache
|
||||
|
||||
pg_search_scope :pg_search, {
|
||||
against: :ignored, # not used since using a tsvector_column
|
||||
using: {
|
||||
tsearch: { tsvector_column: "tsv", dictionary: "spanish", prefix: true }
|
||||
},
|
||||
ignoring: :accents,
|
||||
ranked_by: "(:tsearch)",
|
||||
order_within_rank: (column_names.include?("cached_votes_up") ? "#{table_name}.cached_votes_up DESC" : nil)
|
||||
}
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user