2

我使用弹性搜索,刚刚安装了包含 OneIndexPerLanguage 类的globalize gem ( https://github.com/globalize/globalize#i18n-fallbacks-for-empty-translations ),并且我有以下产品模型:

class Product < ActiveRecord::Base
    translates :product, :product_name, :description, :specification
    include Elasticsearch::Model
    include Elasticsearch::Model::Callbacks
    include Elasticsearch::Model::Globalize::OneIndexPerLanguage

    settings index: { number_of_shards: 1 } do
        mappings dynamic: 'false' do
           indexes :product, analyzer: 'czech'
           indexes :product_name, analyzer: 'czech'
           indexes :manufacturer, analyzer: 'czech'
        end
    end

    globalized_mapping do |locale|
        analyzer = locale == :cs ? 'czech' : 'english'

        indexes :id,          type: 'integer'
        indexes :product_name,        analyzer: analyzer
        indexes :product, analyzer: analyzer
        indexes :description, analyzer: analyzer
        indexes :specification, analyzer: analyzer
    end

    def as_indexed_json(options={})
        as_json(
            only: [:id, :product_name, :product, :manufacturer],
            include: { supplier: { only: :name } 
        })
    end
end

我试图弄清楚和理解的,不幸的是,还没有成功的是以下几点:

  1. 如何将模型属性(产品、产品名称、描述、规范)中的值导入可用的语言环境(cs 和 en)?我尝试“Product.import”来更新elasticsearch,它索引了一些产品,但后来我得到了错误(我猜原因是翻译不存在):

    FAILED (4 prior attempts) with Elasticsearch::Transport::Transport::Errors::NotFound: [404] {"error":"DocumentMissingException[[cs-products][1] [cs-product][1807]: document missing]","status":404}
    
  2. 我每天运行一次延迟作业以更新模型上的这些属性,我如何告诉应用程序不要更改或更新本地化版本(即 cs 和 en),而只更改或更新模型值并将模型值保留为默认情况下,master 和 for users 显示 cs 本地化版本?

  3. 如果翻译为空或可用语言环境不存在,我可以说应用程序,使用我的模型副本吗?

非常感谢您帮助我更好地理解这些功能。米罗斯拉夫

4

0 回答 0