lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ehatc...@apache.org
Subject svn commit: r502480 - in /lucene/solr/trunk/client/ruby/solrb: lib/solr/field.rb test/unit/field_test.rb
Date Fri, 02 Feb 2007 04:33:22 GMT
Author: ehatcher
Date: Thu Feb  1 20:33:21 2007
New Revision: 502480

URL: http://svn.apache.org/viewvc?view=rev&rev=502480
Log:
SOLR-134: Handle Time values using UTC + ISO 8691 representation (contributed by Coda Hale)

Modified:
    lucene/solr/trunk/client/ruby/solrb/lib/solr/field.rb
    lucene/solr/trunk/client/ruby/solrb/test/unit/field_test.rb

Modified: lucene/solr/trunk/client/ruby/solrb/lib/solr/field.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solrb/lib/solr/field.rb?view=diff&rev=502480&r1=502479&r2=502480
==============================================================================
--- lucene/solr/trunk/client/ruby/solrb/lib/solr/field.rb (original)
+++ lucene/solr/trunk/client/ruby/solrb/lib/solr/field.rb Thu Feb  1 20:33:21 2007
@@ -11,6 +11,7 @@
 # limitations under the License.
 
 require 'rexml/document'
+require 'time'
 
 class Solr::Field
   attr_accessor :name
@@ -19,7 +20,9 @@
   def initialize(key_val, opts={})
     raise "first argument must be a hash" unless key_val.kind_of? Hash
     @name = key_val.keys[0].to_s
-    @value = key_val.values[0].to_s
+    @value = key_val.values[0]
+    # Convert any Time values into UTC/XML schema format (which Solr requires).
+    @value = @value.respond_to?(:utc) ? @value.utc.xmlschema : @value.to_s
   end
 
   def to_xml

Modified: lucene/solr/trunk/client/ruby/solrb/test/unit/field_test.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solrb/test/unit/field_test.rb?view=diff&rev=502480&r1=502479&r2=502480
==============================================================================
--- lucene/solr/trunk/client/ruby/solrb/test/unit/field_test.rb (original)
+++ lucene/solr/trunk/client/ruby/solrb/test/unit/field_test.rb Thu Feb  1 20:33:21 2007
@@ -21,6 +21,12 @@
     assert_equal "<field name='creator'>Erik Hatcher</field>", field.to_xml.to_s
   end
   
+  def test_xml_date
+    field = Solr::Field.new :time => Time.now
+    assert_kind_of REXML::Element, field.to_xml
+    assert_match(/<field name='time'>[\d]{4}-[\d]{2}-[\d]{2}T[\d]{2}:[\d]{2}:[\d]{2}Z<\/field>/,
field.to_xml.to_s)
+  end
+  
   def test_i18n_xml
     field = Solr::Field.new :i18nstring => 'Äêâîôû Öëäïöü'
     assert_kind_of REXML::Element, field.to_xml



Mime
View raw message