我有一个大型产品数据库(> 23.000),当我对schema.xml或sunspot的搜索定义进行更改时,我想重新索引所有产品。但有时重新索引失败并出现以下错误:
FloatDomainError: Infinity
from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot/type.rb:142:in `to_i'
from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot/type.rb:142:in `to_indexed'
from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot/field.rb:44:in `to_indexed'
from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot/field_factory.rb:59:in `populate_document'
from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot/indexer.rb:100:in `block in prepare'
from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot/indexer.rb:99:in `each'
from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot/indexer.rb:99:in `prepare'
from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot/indexer.rb:26:in `block in add'
from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot/indexer.rb:26:in `map'
from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot/indexer.rb:26:in `add'
from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot/session.rb:91:in `index'
from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot/session_proxy/abstract_session_proxy.rb:11:in `index'
from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot/lib/sunspot.rb:184:in `index'
from /var/www/domain1/shared/bundle/ruby/1.9.1/gems/newrelic_rpm-3.6.8.168/lib/new_relic/agent/method_tracer.rb:508:in `block in index_with_trace_SolrClient_Sunspot_index'
from /var/www/domain1/shared/bundle/ruby/1.9.1/gems/newrelic_rpm-3.6.8.168/lib/new_relic/agent/method_tracer.rb:259:in `trace_execution_scoped'
from /var/www/domain1/shared/bundle/ruby/1.9.1/gems/newrelic_rpm-3.6.8.168/lib/new_relic/agent/method_tracer.rb:503:in `index_with_trace_SolrClient_Sunspot_index'
from /var/www/domain1/shared/bundle/ruby/1.9.1/bundler/gems/sunspot-5488725cb258/sunspot_rails/lib/sunspot/rails/searchable.rb:401:in `solr_index'
from (irb):4:in `block in irb_binding'
from (irb):4:in `each'
from (irb):4
from /var/www/domain1/shared/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/commands/console.rb:47:in `start'
from /var/www/domain1/shared/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/commands/console.rb:8:in `start'
from /var/www/domain1/shared/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'irb(main):005:0>
我调试了重新索引,并抓住了抛出该错误的产品。但是,当我尝试在该产品上调用.index
方法时,一切正常。
我已经读过这个FloatDomainError: Infinity
,当支持INFINITY
的某个数字数据类型转换为数字数据类型时,会发生这种情况,并且不支持{{1} }。问题是,我无法弄清楚,从哪里开始调试,或究竟是什么导致了这个错误。
修改
我向github repo提交了一个问题:https://github.com/sunspot/sunspot/issues/521
因为它更容易,我也在这里添加来自github的信息:
这是INFINITY
字段的搜索定义(该字段会引发错误):
count_on_hand
我不认为integer :count_on_hand, stored: true do |product|
product.on_hand.nil? ? -1 : product.on_hand
end
字段定义很有用,因为它们只包含标准配置。
然后,我调试了太阳黑子宝石内schema.xml
的{{1}}方法,并在抛出错误时添加了更多输出:
populate_document
如您所见,来自field_factory.rb:57
的{{1}}的值为model.inspect =>
#<Spree::Product id: 19502, name: "Foo Bar", description: "Bar foo", available_on: "2013-12-14 13:30:10", deleted_at: nil, permalink: "foo-bar", meta_description: nil, meta_keywords: "", tax_category_id: 3, shipping_category_id: 1, created_at: "2013-11-26 15:12:25", updated_at: "2013-12-14 13:30:10", count_on_hand: 2>
document.inspect =>
#<RSolr::Xml::Document:0x007ff6f4d58390 @fields=[#<RSolr::Xml::Field:0x007ff6f4d58570 @attrs={:name=>:id}, @value="Spree::Product 19502">,
<RSolr::Xml::Field:0x007ff6f4d58b88 @attrs={:name=>:type}, @value="Spree::Product">,
<RSolr::Xml::Field:0x007ff6f4d58e30 @attrs={:name=>:type}, @value="ActiveRecord::Base">,
<RSolr::Xml::Field:0x007ff6f49a3268 @attrs={:name=>:class_name}, @value="Spree::Product">,
<RSolr::Xml::Field:0x007ff6f47b95b0 @attrs={:name=>:available_on_d}, @value="2013-12-14T13:30:10Z">,
<RSolr::Xml::Field:0x007ff6f47a7220 @attrs={:name=>:price_f}, @value="10.3">],
@attrs={:boost=>1.0}>
@field =>
#<Sunspot::AttributeField:0x00000006081320 @multiple=false, @type=#<Sunspot::Type::IntegerType:0x00000003722dd0>, @name=:count_on_hand, @stored=true, @more_like_this=false, @indexed_name="count_on_hand_is", @reference=nil>
value =>
Infinity
。但是方法中的count_on_hand
变量的值为model.inspect
。此外,2
并未显示在value
中。我不确定,如果这与它有关,但也许这是一个暗示。
问题是,我无法在开发中重现这个问题。上面的错误在生产中被抛出,这就是为什么我对太阳黑子宝石进行猴子修补,并将此代码添加到生产中(以及Airbrake.notify):
Infinity