I'm using Thinking Sphinx for full-text search, following this video.
我正在使用Thinking Sphinx进行全文搜索,关注此视频。
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...
问题是这不起作用。似乎搜索方法只接受作为哈希的条件。我尝试了几种方法,但我对如何将“published_at IS NOT NULL”表示为哈希表示无能为力......
1 个解决方案
#1
24
Was given the solution over at Railscasts
在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.
如果您希望该模型的* all *结果过滤掉published_at IS为NULL的记录,请将“where”published_at IS NOT NULL“'添加到您的define_index块中。
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}
如果它只是有时,添加published_at作为属性,然后sphinx应该将null日期存储为0,所以你可以使用:without => {:published_at => 0}进行过滤
The second solution was what I needed.
第二个解决方案是我需要的。
#1
24
Was given the solution over at Railscasts
在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.
如果您希望该模型的* all *结果过滤掉published_at IS为NULL的记录,请将“where”published_at IS NOT NULL“'添加到您的define_index块中。
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}
如果它只是有时,添加published_at作为属性,然后sphinx应该将null日期存储为0,所以你可以使用:without => {:published_at => 0}进行过滤
The second solution was what I needed.
第二个解决方案是我需要的。