ruby-on-rails - 如何将条件 "IS NOT NULL"添加到 Thinking Sphinx 搜索中

标签 ruby-on-rails ruby full-text-search sphinx thinking-sphinx

我正在使用 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/

相关文章:

ruby-on-rails - 在 has_many :through in RoR 中过滤连接表

ruby - Rack 并发 - rack.multithread、async.callback 或两者兼而有之?

MySQL 全文搜索不匹配

mysql - MATCH AGAINST 在没有连接的情况下跨多个表

ruby-on-rails - 检查当前的设计操作和 View

mysql - 如何正确禁用 MariaDB 的 InnoDB 全文停用词?

ruby-on-rails - 在一个声明中使用 ActiveRecord 序列化多个属性?

ruby-on-rails - Rails 丰富的关联

ruby-on-rails - ruby YAML::加载

ruby - 在 Ruby 中创建一个 Person 类