我在整合searchkick和elasticsearch时遇到问题。这是我到目前为止的内容:
Product records:
id: 1
title: "Electric Fan"
id: 2
title: "Stove"
id: 3
title: "Stoven"
id: 4
title: "Stovener"
这是我的模特
class Product < ActiveRecord::Base
searchkick
end
但是当我进入Rails控制台并尝试搜索时,它只会给我一个结果:
results = Product.search("Stove")
results.map(&:title) # prints ["Stove"]
我不知道为什么它只产生一个结果,实际上它应该产生三个结果。我安装并确保elasticsearch正在运行。
我有什么想念的吗?
TIA
最佳答案
阅读文档:
By default, results must match the entire word - back will not match backpack. You can change this behavior with:
class Product < ActiveRecord::Base
searchkick word_start: [:name]
end
并进行搜索(重新索引后):
Product.search "back", fields: [{name: :word_start}]
消息来源-https://github.com/ankane/searchkick#partial-matches
关于ruby-on-rails - Rails Elasticsearch + Searchkick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26620828/