diff --git a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/common_methods.rb b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/common_methods.rb index 5c3a4f3..a8f2f58 100644 --- a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/common_methods.rb +++ b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/common_methods.rb @@ -28,22 +28,6 @@ module ActsAsSolr #:nodoc: raise "Unknown field_type class: #{field_type.class}: #{field_type}" end end - - # Sets a default value when value being set is nil. - def set_value_if_nil(field_type) - case field_type - when "b", :boolean - return "false" - when "s", "t", "d", :date, :string, :text - return "" - when "f", "rf", :float, :range_float, :double, :decimal - return 0.00 - when "i", "ri", :integer, :range_integer - return 0 - else - return "" - end - end def solr_batch_add(objects) solr_add Array(objects).map{ |a| a.to_solr_doc } diff --git a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/instance_methods.rb b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/instance_methods.rb index 53f8cbb..e6dcf6a 100644 --- a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/instance_methods.rb +++ b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/instance_methods.rb @@ -45,32 +45,23 @@ module ActsAsSolr #:nodoc: # iterate through the fields and add them to the document, configuration[:solr_fields].each do |field_name, options| + next if [self.class.primary_key, "type"].include?(field_name.to_s) + field_boost = options[:boost] || solr_configuration[:default_boost] field_type = get_solr_field_type(options[:type]) solr_name = options[:as] || field_name value = self.send("#{field_name}_for_solr") - value = set_value_if_nil(field_type) if value.to_s == "" - - # add the field to the document, but only if it's not the id field - # or the type field (from single table inheritance), since these - # fields have already been added above. - if field_name.to_s != self.class.primary_key and field_name.to_s != "type" - suffix = get_solr_field_type(field_type) - # This next line ensures that e.g. nil dates are excluded from the - # document, since they choke Solr. Also ignores e.g. empty strings, - # but these can't be searched for anyway: - # http://www.mail-archive.com/solr-dev@lucene.apache.org/msg05423.html - next if value.nil? || value.to_s.strip.empty? - [value].flatten.each do |v| - v = set_value_if_nil(suffix) if value.to_s == "" - - field = Solr::Field.new(:name => "#{solr_name}_#{suffix}", :value => ERB::Util.html_escape(v.to_s)) - processed_boost = validate_boost(field_boost) - field.boost = processed_boost if processed_boost != solr_configuration[:default_boost] - doc << field - end - end + next if value.nil? + + suffix = get_solr_field_type(field_type) + value = Array(value).map{ |v| ERB::Util.html_escape(v) } # escape each value + value = value.first if value.size == 1 + + field = Solr::Field.new(:name => "#{solr_name}_#{suffix}", :value => value) + processed_boost = validate_boost(field_boost) + field.boost = processed_boost if processed_boost != solr_configuration[:default_boost] + doc << field end add_dynamic_attributes(doc) diff --git a/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/dismax.rb b/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/dismax.rb index 031a0fb..7c8ba66 100644 --- a/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/dismax.rb +++ b/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/dismax.rb @@ -16,7 +16,7 @@ class Solr::Request::Dismax < Solr::Request::Standard :alternate_query, :boost_query, :boost_functions]) def initialize(params) - super("search") + super end def to_hash diff --git a/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/standard.rb b/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/standard.rb index 5473fad..aa8d744 100755 --- a/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/standard.rb +++ b/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/standard.rb @@ -17,7 +17,7 @@ class Solr::Request::Standard < Solr::Request::Select :radius, :latitude, :longitude, :spellcheck] def initialize(params) - super('search') + super 'search' raise "Invalid parameters: #{(params.keys - VALID_PARAMS).join(',')}" unless (params.keys - VALID_PARAMS).empty? diff --git a/vendor/plugins/acts_as_solr_reloaded/solr/solr/conf/schema.xml b/vendor/plugins/acts_as_solr_reloaded/solr/solr/conf/schema.xml index 3c4ecf5..67b5aa5 100644 --- a/vendor/plugins/acts_as_solr_reloaded/solr/solr/conf/schema.xml +++ b/vendor/plugins/acts_as_solr_reloaded/solr/solr/conf/schema.xml @@ -53,45 +53,45 @@ - + - + - - - - + + + + - + - + - + - - - - + + + + - + @@ -127,26 +127,24 @@ - - - - - + + + + - - - - - - - - - - - + + + + + + + + + + - + diff --git a/vendor/plugins/acts_as_solr_reloaded/test/unit/common_methods_shoulda.rb b/vendor/plugins/acts_as_solr_reloaded/test/unit/common_methods_shoulda.rb index fd70ed3..c23d64d 100644 --- a/vendor/plugins/acts_as_solr_reloaded/test/unit/common_methods_shoulda.rb +++ b/vendor/plugins/acts_as_solr_reloaded/test/unit/common_methods_shoulda.rb @@ -76,43 +76,6 @@ class CommonMethodsTest < Test::Unit::TestCase end end - context "when determining a default value for a field when it's nil" do - should "return 0.00 for a float" do - assert_equal 0.00, set_value_if_nil("f") - assert_equal 0.00, set_value_if_nil(:float) - assert_equal 0.00, set_value_if_nil("rf") - assert_equal 0.00, set_value_if_nil(:range_float) - end - - should "return 0 for an integer" do - assert_equal 0, set_value_if_nil(:integer) - assert_equal 0, set_value_if_nil(:range_integer) - assert_equal 0, set_value_if_nil("i") - assert_equal 0, set_value_if_nil("ri") - end - - should "return false for a boolean" do - assert_equal "false", set_value_if_nil(:boolean) - assert_equal "false", set_value_if_nil("b") - end - - should "return empty string for strings and text" do - assert_equal "", set_value_if_nil(:string) - assert_equal "", set_value_if_nil(:text) - assert_equal "", set_value_if_nil("t") - assert_equal "", set_value_if_nil("s") - end - - should "return an empty string for a date" do - assert_equal "", set_value_if_nil(:date) - assert_equal "", set_value_if_nil("d") - end - - should "return an empty string for everything else" do - assert_equal "", set_value_if_nil("something") - end - end - context "when determining the record id" do context "on ActiveRecord" do should "return the primary key value" do @@ -125,4 +88,4 @@ class CommonMethodsTest < Test::Unit::TestCase end end end -end \ No newline at end of file +end diff --git a/vendor/plugins/acts_as_solr_reloaded/test/unit/instance_methods_shoulda.rb b/vendor/plugins/acts_as_solr_reloaded/test/unit/instance_methods_shoulda.rb index a1c7f5b..7d4e1b4 100644 --- a/vendor/plugins/acts_as_solr_reloaded/test/unit/instance_methods_shoulda.rb +++ b/vendor/plugins/acts_as_solr_reloaded/test/unit/instance_methods_shoulda.rb @@ -225,18 +225,6 @@ class InstanceMethodsTest < Test::Unit::TestCase assert_not_equal "bogus", doc[:id] end - should "set the default value if field value is nil" do - @instance.name = nil - @instance.expects(:set_value_if_nil).with('s') - @instance.to_solr_doc - end - - should "not include nil values" do - @instance.name = "" - @instance.stubs(:set_value_if_nil).returns "" - assert_nil @instance.to_solr_doc[:name_s] - end - should "escape the contents" do @instance.name = "" assert_equal "<script>malicious()</script>", @instance.to_solr_doc[:name_s] -- libgit2 0.21.2