0
> 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和地點返回不同的計數?

+0

從在這個問題上所用的標籤,我想,太陽黑子是Solr的動力搜索引擎。你有沒有索引任何文件?如果不是,那就可以解釋爲什麼你沒有得到任何點擊... – awendt 2014-09-13 13:21:16

+0

是的,你是對的。我忘了做reindex。請寫下這個問題的答案,所以我選擇了正確的答案。 – 2014-09-13 13:40:42

回答

0

當您可以使用.where找到數據,但無法在您的搜索中獲得任何匹配,那麼您可能只是忘記重新索引您的數據

按照Quick start for the Sunspot Solr client for Ruby

每當你做出改變你的模型如何建立索引,您將需要重建索引數據庫中的任何現有數據。要做到這一點,運行太陽黑子的「重新索引」 rake任務:

rake sunspot:reindex