Sha256: 8b9b64a5fe46ff7a0bc673142e5c81077d12a938684f2d59fffc50d9bfcbc06d

Contents?: true

Size: 944 Bytes

Versions: 11

Compression:

Stored size: 944 Bytes

Contents

module Sunspot
  #
  # QueryFacet instances encapsulate a set of query facet results. Each facet
  # corresponds to a group of rows defined inside a DSL::FieldQuery#facet block.
  #
  class QueryFacet
    def initialize(outgoing_query_facet, row_data) #:nodoc:
      @outgoing_query_facet, @row_data = outgoing_query_facet, row_data
    end

    # 
    # Get the rows associated with this query facet. Returned rows are always
    # ordered by count.
    #
    # ==== Returns
    #
    # Array:: Collection of QueryFacetRow objects, ordered by count
    #
    def rows
      @rows ||=
        begin
          rows = []
          for row in  @outgoing_query_facet.rows
            row_query = row.to_boolean_phrase
            if @row_data.has_key?(row_query)
              rows << QueryFacetRow.new(row.label, @row_data[row_query])
            end
          end
          rows.sort! { |x, y| y.count <=> x.count }
        end
    end
  end
end

Version data entries

11 entries across 11 versions & 4 rubygems

Version Path
Chrononaut-sunspot-client-0.9.4 lib/sunspot/query_facet.rb
UnderpantsGnome-sunspot-0.9.1.1 lib/sunspot/query_facet.rb
kuahyeow-sunspot-0.9.7 lib/sunspot/query_facet.rb
kuahyeow-sunspot-0.9.8 lib/sunspot/query_facet.rb
outoftime-sunspot-0.9.0 lib/sunspot/query_facet.rb
outoftime-sunspot-0.9.1 lib/sunspot/query_facet.rb
outoftime-sunspot-0.9.2 lib/sunspot/query_facet.rb
outoftime-sunspot-0.9.3 lib/sunspot/query_facet.rb
outoftime-sunspot-0.9.4 lib/sunspot/query_facet.rb
outoftime-sunspot-0.9.5 lib/sunspot/query_facet.rb
outoftime-sunspot-0.9.6 lib/sunspot/query_facet.rb