[英]Sunspot/Solr: indexing a time field results in NumberFormatException
我正在嘗試在我的模型中添加一個時間戳字段,以便通過Sunspot / Solr進行索引。 Solr會對此產生阻塞並產生NumberFormatException
:
class Book < ActiveRecord::Base
attr_accessible :lastUpdated, :category, :title # etc...
searchable do
text :title
text :category
time :lastUpdated # mysql 'datetime' field
# etc...
end
end
Jun 06, 2012 10:59:10 AM org.apache.solr.common.SolrException log
SEVERE: java.lang.NumberFormatException: For input string: "2012-01-02T03:29:00Z"
我也嘗試過使用date :lastUpdated
,結果相同。
考慮到我的模型可能有一些偽造的lastUpdated
值,我試着從Time.now
索引結果,並得到相同的結果。
我在外部使用Solr 3.4.0,但使用sunspot.yml
sunspot-installer
提供的“內部”Solr並相應地調整sunspot.yml
重現了同樣的問題。 我的情況似乎很像這里提到的問題,但重新安裝Sunspot / Solr配置似乎並沒有解決它。
編輯 :還試過反對Solr 3.6.0; 同樣的結果。
我懷疑這是由於Sunspot的type.rb中的一個錯誤。 TimeType
定義其indexed_name
是“_d”,而不是“_dt”。 我在我的模型代碼中使用以下方法解決了這個問題:
module Sunspot
module Type
class TimeType < AbstractType
def indexed_name(name) #:nodoc:
"#{name}_dt"
end
end
register TimeType
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.