思考狮身人面像范围返回结果与“空白”的混合

时间:2013-03-22 16:37:52

标签: ruby-on-rails-3 sphinx thinking-sphinx

控制器:

@sites = Site.inspections_enabled_controllers_search.search("test")

@sites.each do |s|
    if s == nil
        puts "WHAT THE ...?"
    end
    ap s #print out the site
end

型号:

has_many :inspections_enabled_controllers, 
            :class_name => 'Controller', 
            :conditions => ['controllers.inspections_enabled = ?', true]

sphinx_scope(:inspections_enabled_controllers_search) {
    {
        :joins => :inspections_enabled_controllers
    }
}

返回:

#<Site:0x000000114618b8> {
              :id => 156,
            :name => "Test Site"
}
WHAT THE ...?
nil
WHAT THE ...?
nil
WHAT THE ...?
nil
#<Site:0x000000111c41a0> {
              :id => 213,
            :name => "TestRail V1.5 - SmartLine"
}
WHAT THE ...?
nil
WHAT THE ...?
nil
WHAT THE ...?
nil
WHAT THE ...?
nil
#<Site:0x00000011461200> {
              :id => 220,
            :name => "Activation Testing"
}

注意SEVEN“ - ”的总数,它们只是数组中的空项。

1 个答案:

答案 0 :(得分:1)

这对我有用

@sites = Site.inspections_enabled_controllers_search.search("test", :retry_stale => 1)

参考: http://pat.github.com/ts/en/searching.html#nils