Sha256: 6a9dec93a67a605e3326c9c262bb9c0dc64b1ee4c8a719566ca241515c936ea1

Contents?: true

Size: 1.58 KB

Versions: 9

Compression:

Stored size: 1.58 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
      # $log.debug "sd:#{solr_data.inspect}"
    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
    
    alias docs results
    alias records results
    alias num_found total
    alias total_hits total
    alias highest_score max_score
  end
  
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
acts_as_solr-1.3.3 lib/search_results.rb
acts_as_solr-1.3.2 lib/search_results.rb
acts_as_solr-1.3.1 lib/search_results.rb
acts_as_solr-1.3.0 lib/search_results.rb
acts_as_solr-1.2.0 lib/search_results.rb
acts_as_solr-1.1.3 lib/search_results.rb
acts_as_solr-1.1.2 lib/search_results.rb
acts_as_solr-1.1.1 lib/search_results.rb
acts_as_solr-1.0.0 lib/search_results.rb