From eca9d0f417b063a5b2d07f3766a680224005cd8d Mon Sep 17 00:00:00 2001 From: "Neil L. Decapia" Date: Fri, 7 Aug 2009 05:54:33 +0800 Subject: [PATCH] Fixing (missed) date and time to_f conversions (related to neildecapia/xapit@331e3d1) --- lib/xapit/indexers/abstract_indexer.rb | 4 ++-- lib/xapit/query_parsers/abstract_query_parser.rb | 4 ++-- spec/xapit/indexers/abstract_indexer_spec.rb | 14 ++++++++------ .../query_parsers/abstract_query_parser_spec.rb | 4 ++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/xapit/indexers/abstract_indexer.rb b/lib/xapit/indexers/abstract_indexer.rb index aaafedd..4c53b6c 100644 --- a/lib/xapit/indexers/abstract_indexer.rb +++ b/lib/xapit/indexers/abstract_indexer.rb @@ -47,9 +47,9 @@ def field_terms(member) @blueprint.field_attributes.map do |name| [member.send(name)].flatten.map do |value| if value.kind_of? Time - value = value.to_i + value = value.to_f elsif value.kind_of? Date - value = value.to_time.to_i + value = value.to_time.to_f end "X#{name}-#{value.to_s.downcase}" end diff --git a/lib/xapit/query_parsers/abstract_query_parser.rb b/lib/xapit/query_parsers/abstract_query_parser.rb index 98e99b3..332308b 100644 --- a/lib/xapit/query_parsers/abstract_query_parser.rb +++ b/lib/xapit/query_parsers/abstract_query_parser.rb @@ -154,9 +154,9 @@ def condition_term(name, value) wildcard_query(value, "X#{name}-") else if value.kind_of? Time - value = value.to_i + value = value.to_f elsif value.kind_of? Date - value = value.to_time.to_i + value = value.to_time.to_f end "X#{name}-#{value.to_s.downcase}" end diff --git a/spec/xapit/indexers/abstract_indexer_spec.rb b/spec/xapit/indexers/abstract_indexer_spec.rb index f389734..16f11ed 100644 --- a/spec/xapit/indexers/abstract_indexer_spec.rb +++ b/spec/xapit/indexers/abstract_indexer_spec.rb @@ -58,18 +58,20 @@ doc.terms.map(&:term).sort.should == %w[term list].sort end - it "should convert time to integer before saving as field term" do + it "should convert time to float before saving as field term" do member = Object.new - stub(member).created_at { Time.now } + t = Time.now + stub(member).created_at { t } @index.field(:created_at) - @indexer.field_terms(member).should == ["Xcreated_at-#{member.created_at.to_i}"] + @indexer.field_terms(member).should == ["Xcreated_at-#{member.created_at.to_f}"] end - it "should convert date to time then integer before saving as field term" do + it "should convert date to time then float before saving as field term" do member = Object.new - stub(member).created_on { Date.today } + d = Date.today + stub(member).created_on { d } @index.field(:created_on) - @indexer.field_terms(member).should == ["Xcreated_on-#{member.created_on.to_time.to_i}"] + @indexer.field_terms(member).should == ["Xcreated_on-#{member.created_on.to_time.to_f}"] end it "should use sortable_serialize for numeric sortable" do diff --git a/spec/xapit/query_parsers/abstract_query_parser_spec.rb b/spec/xapit/query_parsers/abstract_query_parser_spec.rb index 4823902..e0422e8 100644 --- a/spec/xapit/query_parsers/abstract_query_parser_spec.rb +++ b/spec/xapit/query_parsers/abstract_query_parser_spec.rb @@ -12,13 +12,13 @@ it "should convert time into integer before placing in condition term" do time = Time.now parser = Xapit::AbstractQueryParser.new(:conditions => { :time => time }) - parser.condition_terms.should == ["Xtime-#{time.to_i}"] + parser.condition_terms.should == ["Xtime-#{time.to_f}"] end it "should convert date into time then integer before placing in condition term" do date = Date.today parser = Xapit::AbstractQueryParser.new(:conditions => { :date => date }) - parser.condition_terms.should == ["Xdate-#{date.to_time.to_i}"] + parser.condition_terms.should == ["Xdate-#{date.to_time.to_f}"] end it "should give spelling suggestion on full term" do