太阳黑子不工作

时间:2014-09-13 13:09:32

标签: ruby-on-rails ruby-on-rails-4 sunspot sunspot-rails sunspot-solr

> Entity.where(:price => 40000).count
1

> e = Entity.search do
>     with(:price, 0..40001)
> end
> e.results.count
0

模型entity.rb:

class Entity < ActiveRecord::Base
  searchable do
    integer :variant_id
    integer :kind_id
    integer :locality_id
    integer :price
  end
end

为什么Sunspot.search和Where返回不同​​的数量?

1 个答案:

答案 0 :(得分:0)

如果您可以使用.where查找数据但无法在搜索中获得任何匹配,则可能只是忘记重新编制数据索引

根据Quick start for the Sunspot Solr client for Ruby

  

每当您更改模型的索引方式时,都需要为数据库中的任何现有数据重建索引。为此,请运行太阳黑子&#34;重新索引&#34; rake任务:

rake sunspot:reindex