java.lang.NumberFormatException for date/time fields

239 views
Skip to first unread message

George

unread,
Jun 15, 2012, 10:32:34 PM6/15/12
to ruby-s...@googlegroups.com
Hi,

I'm getting a NumberFormatException when trying to index a model with date fields. My model (simplified) looks like:

  searchable do
    text :creator
    time :lastUpdated
  end

I get this with Solr 3.4.0, as well as with Sunspot's bundled Solr server and default schema. Thinking that perhaps I had some bad date fields in my DB, I tried indexing Time.now and got the same results.


Jun 15, 2012 10:27:40 PM org.apache.solr.common.SolrException log
SEVERE: java.lang.NumberFormatException: For input string: "2011-08-03T18:45:49Z"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1241)
at java.lang.Double.parseDouble(Double.java:540)
at org.apache.solr.schema.TrieField.createField(TrieField.java:384)
at org.apache.solr.schema.SchemaField.createField(SchemaField.java:104)
at org.apache.solr.update.DocumentBuilder.addField(DocumentBuilder.java:203)
at org.apache.solr.update.DocumentBuilder.toDocument(DocumentBuilder.java:276)
at org.apache.solr.update.processor.RunUpdateProcessor.processAdd(RunUpdateProcessorFactory.java:60)
at org.apache.solr.handler.XMLLoader.processUpdate(XMLLoader.java:158)
at org.apache.solr.handler.XMLLoader.load(XMLLoader.java:79)
at org.apache.solr.handler.ContentStreamHandlerBase.handleRequestBody(ContentStreamHandlerBase.java:67)
at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:129)
at org.apache.solr.core.SolrCore.execute(SolrCore.java:1368)
at org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:356)
at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:252)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:399)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:945)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)


Thanks for any help.


George

unread,
Jun 16, 2012, 8:52:57 PM6/16/12
to ruby-s...@googlegroups.com
I'm new to Ruby, so take this with a grain of salt, but I suspect there's a bug in type.rb: The indexed_name for "TimeType" should be "_dt", not " _d". I've worked around this by using the following in my model:

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

Mauro Asprea

unread,
Jun 17, 2012, 6:05:28 AM6/17/12
to ruby-s...@googlegroups.com
Honestly I don't have a clue about why Solr is throwing that, but because I see 'TrieField' you should try adding ':trie => true' in the field like this:

time :lastUpdated, :trie => true

Try that and see if it works ;)
June 16, 2012 4:32 AM
Hi,

I'm getting a NumberFormatException when trying to index a model with date fields. My model (simplified) looks like:




Thanks for any help.


--
You received this message because you are subscribed to the Google Groups "Sunspot" group.
To view this discussion on the web visit https://groups.google.com/d/msg/ruby-sunspot/-/dgbySTTPt-QJ.
To post to this group, send email to ruby-s...@googlegroups.com.
To unsubscribe from this group, send email to ruby-sunspot...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ruby-sunspot?hl=en.

--
Mauro Asprea

E-Mail: mauro...@gmail.com
Mobile: +34 654297582
Skype: mauro.asprea

George

unread,
Jun 17, 2012, 9:24:40 AM6/17/12
to ruby-s...@googlegroups.com
Hi Mauro,

Thanks for your suggestion. I actually posted a work-around yesterday, but Google Groups didn't like my post for some reason. Here's what I came up with: http://stackoverflow.com/a/11068152/93995

I noticed that Sunspot was storing time fields with "_d" rather than "_dt". Changing it to use "_dt" seems to do the trick.

I just tried out your suggestion of using "trie", and that also works. I imagine that "trie" is required if you want to compare dates. I'm new to Sunspot (and Ruby in general), so perhaps someone could answer authoritatively on whether using "_d" for dates (without "trie") is in fact a bug or not. The documented examples do not work out of the box, so I suspect that at the very least a doc update is needed.

Thanks again.
Reply all
Reply to author
Forward
0 new messages