diff --git a/client/ruby/solr-ruby/lib/solr/request/standard.rb b/client/ruby/solr-ruby/lib/solr/request/standard.rb index e990cf3ef50..33b78f4035c 100755 --- a/client/ruby/solr-ruby/lib/solr/request/standard.rb +++ b/client/ruby/solr-ruby/lib/solr/request/standard.rb @@ -71,18 +71,20 @@ class Solr::Request::Standard < Solr::Request::Select hash["facet.missing"] = @params[:facets][:missing] hash["facet.mincount"] = @params[:facets][:mincount] hash["facet.prefix"] = @params[:facets][:prefix] - @params[:facets][:fields].each do |f| - if f.kind_of? Hash - key = f.keys[0] - value = f[key] - hash["facet.field"] << key - hash["f.#{key}.facet.sort"] = (value[:sort] == :count) if value[:sort] - hash["f.#{key}.facet.limit"] = value[:limit] - hash["f.#{key}.facet.missing"] = value[:missing] - hash["f.#{key}.facet.mincount"] = value[:mincount] - hash["f.#{key}.facet.prefix"] = value[:prefix] - else - hash["facet.field"] << f + if @params[:facets][:fields] # facet fields are optional (could be facet.query only) + @params[:facets][:fields].each do |f| + if f.kind_of? Hash + key = f.keys[0] + value = f[key] + hash["facet.field"] << key + hash["f.#{key}.facet.sort"] = (value[:sort] == :count) if value[:sort] + hash["f.#{key}.facet.limit"] = value[:limit] + hash["f.#{key}.facet.missing"] = value[:missing] + hash["f.#{key}.facet.mincount"] = value[:mincount] + hash["f.#{key}.facet.prefix"] = value[:prefix] + else + hash["facet.field"] << f + end end end end diff --git a/client/ruby/solr-ruby/test/unit/standard_request_test.rb b/client/ruby/solr-ruby/test/unit/standard_request_test.rb index 85dc7821640..05ffe95f5c2 100755 --- a/client/ruby/solr-ruby/test/unit/standard_request_test.rb +++ b/client/ruby/solr-ruby/test/unit/standard_request_test.rb @@ -55,6 +55,17 @@ class StandardRequestTest < Test::Unit::TestCase assert_match /debugQuery/, request.to_s end + def test_only_facet_query + request = Solr::Request::Standard.new(:query => 'query', + :facets => { + :queries => ["q1", "q2"], + } + ) + + hash = request.to_hash + assert_equal ["q1", "q2"], hash["facet.query"] + end + def test_facet_params_all request = Solr::Request::Standard.new(:query => 'query', :facets => {