Exempt nil parameters from the Solr request

git-svn-id: https://svn.apache.org/repos/asf/incubator/solr/trunk@496863 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2007-01-16 21:28:44 +00:00
parent 4c8747190b
commit 4f85c3998b
2 changed files with 10 additions and 3 deletions

View File

@ -40,9 +40,9 @@ module Solr
http_params = []
raw_params.each do |key,value|
if value.respond_to? :each
value.each { |v| http_params << "#{key}=#{ERB::Util::url_encode(v)}" }
value.each { |v| http_params << "#{key}=#{ERB::Util::url_encode(v)}" unless v.nil?}
else
http_params << "#{key}=#{ERB::Util::url_encode(value)}"
http_params << "#{key}=#{ERB::Util::url_encode(value)}" unless value.nil?
end
end

View File

@ -41,8 +41,15 @@ class StandardRequestTest < Test::Unit::TestCase
assert_equal ['fq1','fq2'], request.to_hash[:fq]
assert_equal "id,title,score", request.to_hash[:fl]
end
def test_empty_params
request = Solr::Request::Standard.new(:query => 'query', :debug_query => false)
assert_nil request.to_hash[:rows]
assert_no_match /rows/, request.to_s
assert_match /debugQuery/, request.to_s
end
def test_facet_params
def test_facet_params_all
request = Solr::Request::Standard.new(:query => 'query',
:facets => {
:fields => [:genre,