如何在Thinking Sphinx搜索中添加条件“IS NOT NULL”
-
06-07-2019 - |
题
我正在使用Thinking Sphinx进行全文搜索,请参阅此视频。
我想做以下事情:
@articles = Article.search(params[:search], :conditions => "published_at IS NOT NULL", :order => :created_at)
问题是这不起作用。似乎搜索方法只接受哈希条件。我尝试了几种方法,但我对如何表示“published_at IS NOT NULL”无能为力。作为哈希......
解决方案
在 Railscasts 上获得解决方案
如果您希望该模型的* all *结果过滤掉published_at IS为NULL的记录,请添加'where',published_at IS NOT NULL"'到你的define_index块。
如果只是有时,请将published_at添加为属性,然后sphinx应将空日期存储为0,因此您可以使用:without =>进行过滤{:published_at => 0}
第二种解决方案就是我所需要的。
不隶属于 StackOverflow