How do i index arabic profile translations with sunspot solr. Can i use globalize and sunspot or should use some other approach?
models/profile.rb
translates :name, :description
validates :name
validates :description
searchable do
text :name
text :description
end
You can define separate fields for each of your locales in your search block:
I18n.available_locales.each do |locale|
# Separate name field for each locale
text "name_#{locale}".to_sym do
# read_Attribute is defined by Globalize.
read_attribute(:name, locale: locale)
end
text "description_#{locale}".to_sym do
read_attribute(:description, locale: locale)
end
end
When you are doing a search, you have to specify which locale you want to use:
# Search by actual locale
search = Sunspot.search(Profile) do
fulltext "search term" do
fields "name_#{I18n.locale}".to_sym,
"description_#{I18n.locale}".to_sym,
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With