searchkick查询得到错误的结果。
我在数据库中有一条记录:
2.2.0 :047 > Product.first
#<Product id: 1, title: "Ball", description: "<p>Ball</p>\r\n", price: 10, material: "lalala", created_at: "2015-04-21 04:30:53", updated_at: "2015-04-21 04:30:53", preview: "images__1_.jpg", count: 20>
在 Controller
Product
和操作search
中,我有以下代码: def search
@products = Product.search "*", where:
{
count: 10..18
}
end
然后,得到具有该值的count的获取结果。
但是,在db count = 20的情况下,总是出现错误的结果。不知道为什么
最佳答案
我得到的结果不正确,因为在模型中没有哈希,因此需要重新索引模型。
在模型中:
def search_data
{
count: count,
price: price,
title: title,
category_id: categories.map($:id)
}
end
然后,在Rails控制台中写道:
Product.reindex
关于ruby-on-rails - 查询查询结果错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29765968/