如何将具有范围的搜索过滤器添加到 Searchkick? (Rails 5)

How to add a search filter with scope to Searchkick? (Rails 5)

我在 Rails 5 和 Searchkick gem 上使用 Ruby。

我现在在我的控制器中使用它,它工作正常:

@blogs = Blog.search(query, where:{published_at: nil})

但我想使用一个非零的范围,所以:

 scope :published, ->{ where.not(published_at: nil )}

但我不知道如何让它在我的控制器中工作,我试过了,但它不起作用

 @blogs = Blog.search(query, where.not:{published_at: nil})

如何获取那些不为nil的记录?

这应该适合你:

@blogs = Blog.search(query, where: { published_at: { not: nil } })

来源:Searchkick ~ Querying