Rails 3.2.3 mongoid 2.4.4 sunspot_mongoid 0.4.1 sunspot_rails 1.3.1 sunspot 1.3.1
在 Content 中用了数字 id,然后发现数字 id 索引出来会报 BSON::InvalidObjectId: illegal ObjectId format 的错误。 部分测试数据使用 BSON 格式的 id,搜索没有发现异常
irb(main):268:0> r = Content.solr_search { fulltext 'http' }
=> <Sunspot::Search:{:fq=>["type:Content"], :q=>"http", :fl=>"* score", :qf=>"text_text", :defType=>"dismax", :start=>0, :rows=>30}>
irb(main):269:0> r.results
BSON::InvalidObjectId: illegal ObjectId format: 3433622835126607
from /opt/App/ruby192/lib/ruby/gems/1.9.1/gems/bson-1.5.2/lib/bson/types/object_id.rb:126:in `from_string'
from /opt/App/ruby192/lib/ruby/gems/1.9.1/gems/sunspot_mongoid-0.4.1/lib/sunspot/mongoid.rb:39:in `block in load_all'
from /opt/App/ruby192/lib/ruby/gems/1.9.1/gems/sunspot_mongoid-0.4.1/lib/sunspot/mongoid.rb:39:in `map'
from /opt/App/ruby192/lib/ruby/gems/1.9.1/gems/sunspot_mongoid-0.4.1/lib/sunspot/mongoid.rb:39:in `load_all'
from /opt/App/ruby192/lib/ruby/gems/1.9.1/gems/sunspot-1.3.1/lib/sunspot/search/abstract_search.rb:228:in `block in populate_hits'
from /opt/App/ruby192/lib/ruby/gems/1.9.1/gems/sunspot-1.3.1/lib/sunspot/search/abstract_search.rb:224:in `each_pair'
from /opt/App/ruby192/lib/ruby/gems/1.9.1/gems/sunspot-1.3.1/lib/sunspot/search/abstract_search.rb:224:in `populate_hits'
from /opt/App/ruby192/lib/ruby/gems/1.9.1/gems/sunspot-1.3.1/lib/sunspot/search/hit.rb:90:in `result'
from /opt/App/ruby192/lib/ruby/gems/1.9.1/gems/sunspot-1.3.1/lib/sunspot/search/abstract_search.rb:275:in `block in verified_hits'
from /opt/App/ruby192/lib/ruby/gems/1.9.1/gems/sunspot-1.3.1/lib/sunspot/search/paginated_collection.rb:50:in `select'
from /opt/App/ruby192/lib/ruby/gems/1.9.1/gems/sunspot-1.3.1/lib/sunspot/search/paginated_collection.rb:50:in `method_missing'
from /opt/App/ruby192/lib/ruby/gems/1.9.1/gems/sunspot-1.3.1/lib/sunspot/search/abstract_search.rb:275:in `verified_hits'
from /opt/App/ruby192/lib/ruby/gems/1.9.1/gems/sunspot-1.3.1/lib/sunspot/search/abstract_search.rb:59:in `results'
from (irb):2
from /opt/App/ruby192/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/commands/console.rb:47:in `start'
from /opt/App/ruby192/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/commands/console.rb:8:in `start'
from /opt/App/ruby192/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'irb(main):003:0>
而直接请求可以找到记录(ps:之前也报 InvalidObjectId,加了 field :_id, :type => Integer 后正常)
Content.find('3433622835126607')
=> #<Content _id: 3433622835126607>