Permalink
Browse files

The sortable converter should be type aware

  • Loading branch information...
1 parent f12757c commit 72624ca31b1b58836b69cd8777bb449cb4950fd3 @jcoyne jcoyne committed Mar 6, 2013
Showing with 17 additions and 4 deletions.
  1. +8 −1 lib/solrizer/default_descriptors.rb
  2. +1 −1 lib/solrizer/field_mapper.rb
  3. +8 −2 spec/units/common_spec.rb
@@ -36,7 +36,7 @@ def self.symbol
# Produces _si suffix
def self.sortable
- @sortable ||= Descriptor.new(:string, :indexed)
+ @sortable ||= Descriptor.new(sortable_field_definition, converter: searchable_converter, requires_type: true)
end
# Fields that are both stored and sortable
@@ -78,6 +78,13 @@ def self.stored_searchable_field_definition
end
end
+ def self.sortable_field_definition
+ lambda do |type|
+ vals = [type, :indexed]
+ vals
+ end
+ end
+
def self.searchable_converter
lambda do |type|
case type
@@ -127,7 +127,7 @@ def solr_name(field_name, *opts)
elsif opts.empty?
[:stored_searchable, {type: :text}]
else
- [opts[0], opts[1] || {}]
+ [opts[0], opts[1] || {type: :string}]
end
indexer(index_type).name_and_converter(field_name, args).first
View
@@ -15,13 +15,19 @@ class Foo
Foo.create_and_insert_terms('my_name', 'value', [:displayable, :searchable, :sortable], solr_doc)
solr_doc.should == {'my_name_ssm' => ['value'], 'my_name_si' => ['value'], 'my_name_teim' => ['value']}
end
-
+
it "should handle dates that are searchable" do
solr_doc = {}
Foo.create_and_insert_terms('my_name', Date.parse('2013-01-10'), [:stored_searchable], solr_doc)
solr_doc.should == {'my_name_dtsim' => ['2013-01-10T00:00:00Z']}
end
+ it "should handle dates that are stored_sortable" do
+ solr_doc = {}
+ Foo.create_and_insert_terms('my_name', Date.parse('2013-01-10'), [:stored_sortable], solr_doc)
+ solr_doc.should == {'my_name_dtsi' => ['2013-01-10T00:00:00Z']}
+ end
+
it "should handle dates that are displayable" do
solr_doc = {}
Foo.create_and_insert_terms('my_name', Date.parse('2013-01-10'), [:displayable], solr_doc)
@@ -31,6 +37,6 @@ class Foo
it "should handle dates that are sortable" do
solr_doc = {}
Foo.create_and_insert_terms('my_name', Date.parse('2013-01-10'), [:sortable], solr_doc)
- solr_doc.should == {'my_name_si' => ['2013-01-10']}
+ solr_doc.should == {'my_name_dti' => ['2013-01-10T00:00:00Z']}
end
end

0 comments on commit 72624ca

Please sign in to comment.