rails:如何在elasticsearch中设置locale使用耐嚼的gem

时间:2016-05-09 13:50:06

标签: ruby-on-rails ruby ruby-on-rails-4 elasticsearch chewy-gem

我使用gem Chewy的elasticsearch。我使用Globalize gem进行翻译。 我有一个模型位置,并翻译位置的属性名称。但是耐嚼只更新最后的数据,不要用不同的语言环境更新数据。 我想耐心更新两个数据(使用locale:en,:fr,..) 如何在elasticsearch中设置或配置全球化

在文件location_index.rb

class LocationsIndex < Chewy::Index
  settings analysis: {
    analyzer: {
      folding: {
          tokenizer: "standard",
          filter:  [ "lowercase", "asciifolding" ]
        },
      sorted: {
        tokenizer: 'keyword',
        filter: ['lowercase', 'asciifolding']
      }
    }
  }

  define_type Location do
    field :name, type: 'string', analyzer: 'standard' do
      field :folded, type: 'string', analyzer:   "folding"
    end
    field :location, type: 'geo_point', value: ->{ {lat: lat, lon: lon} }
  end

  define_type Place do
    field :name, type: 'string', analyzer: 'standard' do
      field :folded, type: 'string', analyzer:   "folding"
    end
    field :address, type: 'string', analyzer: 'standard' do
      field :address, type: 'string', analyzer: 'folding'
    end
    field :category, index: 'not_analyzed', value: ->{ category.name if category.present?}
    field :location, type: 'geo_point', value: ->{ {lat: lat, lon: lon} }
  end

end

0 个答案:

没有答案