Skip to content

Commit

Permalink
Fixing (missed) date and time to_f conversions (related to
Browse files Browse the repository at this point in the history
  • Loading branch information
neildecapia committed Aug 6, 2009
1 parent c88b123 commit eca9d0f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/xapit/indexers/abstract_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/xapit/query_parsers/abstract_query_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions spec/xapit/indexers/abstract_indexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/xapit/query_parsers/abstract_query_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eca9d0f

Please sign in to comment.