Skip to content

Commit

Permalink
Should handle empty dates
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Nov 28, 2012
1 parent e641a48 commit f8cc361
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/solrizer/field_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def solr_names_and_values(field_name, field_value, field_type, index_types)

# Add mapped name & value, unless it's a duplicate
values = (results[name] ||= [])
values << value unless values.include?(value)
values << value unless value.nil? || values.include?(value)
end

results
Expand Down Expand Up @@ -331,7 +331,11 @@ class Default < FieldMapper
index_as :searchable, :default => true do |t|
t.default :suffix => '_t'
t.date :suffix => '_dt' do |value|
value.is_a?(Date) ? DateTime.parse(value.to_s).to_time.utc.iso8601 : DateTime.parse(value).to_time.utc.iso8601
if value.is_a?(Date)
DateTime.parse(value.to_s).to_time.utc.iso8601
elsif !value.empty?
DateTime.parse(value).to_time.utc.iso8601
end
end
t.string :suffix => '_t'
t.text :suffix => '_t'
Expand Down
1 change: 1 addition & 0 deletions spec/units/field_mapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ class TestMapperLoading < Solrizer::FieldMapper
@mapper.solr_names_and_values('foo', "2012-11-06", :date, []).should == { 'foo_dt' =>["2012-11-06T00:00:00Z"] }
@mapper.solr_names_and_values('foo', "November 6th, 2012", :date, []).should == { 'foo_dt' =>["2012-11-06T00:00:00Z"] }
@mapper.solr_names_and_values('foo', Date.parse("6 Nov. 2012"), :date, []).should == { 'foo_dt' =>["2012-11-06T00:00:00Z"] }
@mapper.solr_names_and_values('foo', '', :date, []).should == { 'foo_dt' => [] }
end

it "should support displayable, facetable, sortable, unstemmed" do
Expand Down

0 comments on commit f8cc361

Please sign in to comment.