我将 Searchkick 与 Elasticsearch 结合使用来获取带有搜索词的产品。
我正在尝试向其中添加一个 WHERE NOT
子句,这样它就不会返回任何 regular_price
为空的产品。
@products = Product.search(
search,
where: {
regular_price: {
not: "null" # I have also tried nil, both won't work
}
},
page: params[:page],
per_page: per_page,
)
搜索忽略我的 WHERE NOT
子句。
我也将不胜感激一些调试技巧。
编辑:
所以我尝试使用以下内容,但现在它只返回适合搜索的每个产品。忽略搜索的 WHERE NOT
部分。
@products = Product.search(
search,
where: {
regular_price: {
_not: "null"
}
},
page: params[:page],
per_page: per_page,
)
更新:
我尚未找到此问题的解决方案,因此我继续采用不同的方法。过滤掉 regular_price
为 0 的产品。
最佳答案
@products = Product.search(
search,
where: {
regular_price: {
_not: nil
}
},
page: params[:page],
per_page: per_page,
)
只需将"null"
替换为nil
,它就会过滤掉没有regular_price的产品。
关于ruby-on-rails - 如何将 "where not"子句与 searchkick 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62225170/