5

我如何使用太阳黑子 solr 索引阿拉伯文的个人资料翻译。我可以使用 globalize 和 sunspot 还是应该使用其他方法?

模型/profile.rb

translates :name, :description
validates :name
validates :description

searchable do
  text :name
  text :description
end
4

1 回答 1

2

您可以在搜索块中为每个语言环境定义单独的字段:

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

当您进行搜索时,您必须指定要使用的语言环境:

# 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
于 2014-06-10T19:17:19.200 回答