如何添加条件“IS NOT NULL”思考狮身人面像的搜索 [英] How do I add the condition "IS NOT NULL" to a Thinking Sphinx search
问题描述
我正在使用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}
第二个解决方案是我需要的。
I'm using Thinking Sphinx for full-text search, following this video.
I'd like to do the following:
@articles = Article.search(params[:search], :conditions => "published_at IS NOT NULL", :order => :created_at)
The problem is that this doesn't work. It seems that the search method only accepts conditions that are a hash. I've tried a couple of ways, but I am clueless as to how I can represent "published_at IS NOT NULL" as a hash...
Was given the solution over at Railscasts
If you want *all* results for that model to filter out records where published_at IS NULL, add 'where "published_at IS NOT NULL"' to your define_index block.
If it's only sometimes, add published_at as an attribute, and then sphinx should store null dates as 0's, so you can filter using :without => {:published_at => 0}
The second solution was what I needed.
这篇关于如何添加条件“IS NOT NULL”思考狮身人面像的搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!