我有一个Item
属于模型的Product
模型。我想Items
使用product.platform
. 我设置了一个委托方法item.product_platform
并索引了它的输出。
似乎轮胎 / ES 仅按一个单词过滤,并且仅使用小写字母。所以:
item.product_platform = "Nintendo Wii"
filter :term, product_platform: "wii" # works
filter :term, product_platform: "nintendo" # works
filter :term, product_platform: "Wii" # does not work
filter :term, product_platform: "Nintendo" # does not work
filter :term, product_platform: "nintendo wii" # does not work
filter :term, product_platform: "Nintendo Wii" # does not work
但是当我传入一个精确的字符串时,我希望它返回一个结果,比如“Nintendo Wii”。
这是我的item.rb
belongs_to :product
delegate :platform, to: :product, prefix: true
def self.search(params)
tire.search do
query { string params[:query] } if params[:query].present?
filter :term, product_platform: params[:platform] if params[:platform]
end
end
def to_indexed_json
to_json(include: :product, methods: :product_platform)
end
这是我的映射:
mapping date_detection: false do
indexes :id, type: 'integer'
indexes :user_id, type: 'integer'
indexes :product_id, type: 'integer'
indexes :product_platform
end