lib/sunspot/query/query_facet.rb in sunspot-0.9.8 vs lib/sunspot/query/query_facet.rb in sunspot-0.10.0

- old
+ new

@@ -10,17 +10,17 @@ # grouping for the facet at the Sunspot level, which provides a nicer and # more consistent API in Sunspot; Solr does not provide any grouping for # query facet rows, instead returning each requested row individually, keyed # by the boolean phrase used in the facet query. # - class QueryFacet + class QueryFacet #:nodoc: attr_reader :name #:nodoc: attr_reader :field #:nodoc: + attr_reader :options #:nodoc: - def initialize(name, setup = nil) #:nodoc: - @name = name - @setup = setup + def initialize(name, options, setup = nil) #:nodoc: + @name, @options, @setup = name, options, setup @components = [] end # # Add a QueryFacetRow to this facet. The label argument becomes the value @@ -49,14 +49,19 @@ # # Hash:: Solr params hash # def to_params #:nodoc: components = @components.map { |component| component.to_boolean_phrase } - components = components.first if components.length == 1 - { - :facet => 'true', - :"facet.query" => components - } + components.compact! + if components.empty? + {} + else + components = components.first if components.length == 1 + { + :facet => 'true', + :"facet.query" => components + } + end end # # Get query facet rows (used when constructing results) #