Class: Sunspot::Search::QueryFacet

Inherits:
Object
  • Object
show all
Defined in:
lib/sunspot/search/query_facet.rb

Direct Known Subclasses

FieldFacet

Defined Under Namespace

Classes: RequestedFacet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, search, options) ⇒ QueryFacet

:nodoc:



8
9
10
11
# File 'lib/sunspot/search/query_facet.rb', line 8

def initialize(name, search, options) #:nodoc:
  @name, @search, @options = name, search, options
  @requested_facets = []
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/sunspot/search/query_facet.rb', line 6

def name
  @name
end

Instance Method Details

#add_row(label, boolean_phrase) ⇒ Object

:nodoc:



34
35
36
# File 'lib/sunspot/search/query_facet.rb', line 34

def add_row(label, boolean_phrase) #:nodoc:
  @requested_facets << RequestedFacet.new(label, boolean_phrase)
end

#rows(options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sunspot/search/query_facet.rb', line 13

def rows(options = {})
  @rows ||=
    begin
      data = @search.facet_response['facet_queries']
      rows = []
      minimum_count =
        case
        when @options[:minimum_count] then @options[:minimum_count]
        when @options[:zeros] then 0
        else 1
        end
      @requested_facets.each do |requested_facet|
        count = data[requested_facet.boolean_phrase] || 0
        if count >= minimum_count
          rows << FacetRow.new(requested_facet.label, count, self)
        end
      end
      sort_rows!(rows)
    end
end