我正在使用 Thinking Sphinx 进行全文搜索,关注 this video .
我想做以下事情:
@articles = Article.search(params[:search], :conditions => "published_at IS NOT NULL", :order => :created_at)
问题是这行不通。搜索方法似乎只接受散列条件。我尝试了几种方法,但我对如何将“published_at IS NOT NULL”表示为哈希一无所知...
最佳答案
在 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}
第二种解决方案正是我所需要的。
关于ruby-on-rails - 如何将条件 "IS NOT NULL"添加到 Thinking Sphinx 搜索中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/258378/