rubysolrlucenesunspotsunspot-solr

Sunspot/Solr: indexing a time field results in NumberFormatException


I'm trying to add a timestamp field to my model for indexing by Sunspot/Solr. Solr chokes on this and produces a 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"

I've also tried using date :lastUpdated with the same results.

Thinking that perhaps my model has some bogus lastUpdated values, I tried indexing the results from Time.now, and got the same results.

I'm using Solr 3.4.0 externally, but have reproduced the same problem using the "internal" Solr provided by sunspot-installer, and adjusting sunspot.yml accordingly. My situation seems a lot like the problem mentioned here, but re-installing the Sunspot/Solr config does not seem to fix it.

Edit: have also tried against Solr 3.6.0; same result.


Solution

  • I suspect that this is due to a bug in Sunspot's type.rb. TimeType defines its indexed_nameto be "_d", rather than "_dt". I've worked around this in my model code with the following:

    module Sunspot
      module Type
        class TimeType < AbstractType
          def indexed_name(name) #:nodoc:
            "#{name}_dt"
          end
        end
        register TimeType
      end
    end