Sha256: c20474f6e5a27cdece9582bd3d54a18c7e8dba593d41fc305785e8a29d2e0b42

Contents?: true

Size: 1.62 KB

Versions: 4

Compression:

Stored size: 1.62 KB

Contents

module ActsAsSolr #:nodoc:

  # TODO: Possibly looking into hooking it up with Solr::Response::Standard
  #
  # Class that returns the search results with four methods.
  #
  #   books = Book.find_by_solr 'ruby'
  #
  # the above will return a SearchResults class with 4 methods:
  #
  # docs|results|records: will return an array of records found
  #
  #   books.records.empty?
  #   => false
  #
  # total|num_found|total_hits: will return the total number of records found
  #
  #   books.total
  #   => 2
  #
  # facets: will return the facets when doing a faceted search
  #
  # max_score|highest_score: returns the highest score found
  #
  #   books.max_score
  #   => 1.3213213
  #
  #
  class SearchResults
    def initialize(solr_data={})
      @solr_data = solr_data
    end

    # Returns an array with the instances. This method
    # is also aliased as docs and records
    def results
      @solr_data[:docs]
    end

    # Returns the total records found. This method is
    # also aliased as num_found and total_hits
    def total
      @solr_data[:total]
    end

    # Returns the facets when doing a faceted search
    def facets
      @solr_data[:facets]
    end

    # Returns the highest score found. This method is
    # also aliased as highest_score
    def max_score
      @solr_data[:max_score]
    end

    def query_time
      @solr_data[:query_time]
    end

    # Returns the highlighted fields which one has asked for..
    def highlights
        @solr_data[:highlights]
    end

    alias docs results
    alias records results
    alias num_found total
    alias total_hits total
    alias highest_score max_score
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
acts_as_solr_reloaded-1.3.0 lib/acts_as_solr/search_results.rb
acts_as_solr_reloaded-1.2.0 lib/acts_as_solr/search_results.rb
acts_as_solr_reloaded-1.1.0 lib/acts_as_solr/search_results.rb
acts_as_solr_reloaded-1.0.0 lib/acts_as_solr/search_results.rb