Sha256: 573e91c0ae4190ee4426e8c4bbf05749a6653c2c3de71f955dad233b25ce3afa

Contents?: true

Size: 1.44 KB

Versions: 4

Compression:

Stored size: 1.44 KB

Contents

require 'sunspot/search/paginated_collection'
require 'sunspot/search/hit_enumerable'

module Sunspot
  module Search #:nodoc:
    
    # 
    # This class encapsulates the results of a Solr search. It provides access
    # to search results, total result count, facets, and pagination information.
    # Instances of Search are returned by the Sunspot.search and
    # Sunspot.new_search methods.
    #
    class AbstractSearch
      # 
      # Retrieve all facet objects defined for this search, in order they were
      # defined. To retrieve an individual facet by name, use #facet()
      #
      attr_reader :stats

      def initialize(connection, setup, query, configuration) #:nodoc:
        @connection, @setup, @query = connection, setup, query
        @query.paginate(1, configuration.pagination.default_per_page)

        @stats = []
        @stats_by_name = {}

        @facets = []
        @facets_by_name = {}

        @groups_by_name = {}
        @groups = []
      end


      def stat(name)
        if name
          @stats_by_name[name.to_sym]
        end
      end

      def stat_response #:nodoc:
        @solr_result['stats']
      end

      def add_field_stat(field, options = {}) #:nodoc:
        name = (options[:name] || field.name)
        add_stat(name, StatFacet.new(field, self, options))
      end
      
      def add_stat(name, stat)
        @stats << stat
        @stats_by_name[name.to_sym] = stat
      end
      
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sunspot_stats-0.0.5 lib/search/stat_search.rb
sunspot_stats-0.0.4 lib/search/stat_search.rb
sunspot_stats-0.0.3 lib/search/stat_search.rb
sunspot_stats-0.0.2 lib/search/stat_search.rb