Sha256: 45fde6af2efc64f43eaf98317bccfe86991dc5614d6c6958f39ced812dad1423

Contents?: true

Size: 1.54 KB

Versions: 26

Compression:

Stored size: 1.54 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
    
    alias docs results
    alias records results
    alias num_found total
    alias total_hits total
    alias highest_score max_score
  end
  
end

Version data entries

26 entries across 26 versions & 6 rubygems

Version Path
honkster-acts_as_solr-0.1.0 lib/acts_as_solr/search_results.rb
honkster-acts_as_solr-0.2.0 lib/acts_as_solr/search_results.rb
honkster-acts_as_solr-0.2.1 lib/acts_as_solr/search_results.rb
honkster-acts_as_solr-0.2.2 lib/acts_as_solr/search_results.rb
honkster-acts_as_solr-0.2.3 lib/acts_as_solr/search_results.rb
honkster-acts_as_solr-0.2.4 lib/acts_as_solr/search_results.rb
honkster-acts_as_solr-0.2.5 lib/acts_as_solr/search_results.rb
honkster-acts_as_solr-0.3.4 lib/acts_as_solr/search_results.rb
jbasdf-acts_as_solr-0.3.3 lib/acts_as_solr/search_results.rb
jbasdf-jbasdf-acts_as_solr-0.4.0 lib/acts_as_solr/search_results.rb
jbasdf-muck-solr-0.4.0 lib/acts_as_solr/search_results.rb
jbasdf-muck-solr-0.4.1 lib/acts_as_solr/search_results.rb
jbasdf-muck-solr-0.4.2 lib/acts_as_solr/search_results.rb
onemorecloud-websolr-rails-1.1.1 lib/search_results.rb
muck-solr-3.0.1 lib/acts_as_solr/search_results.rb
muck-solr-3.0.0 lib/acts_as_solr/search_results.rb
muck-solr-0.4.7 lib/acts_as_solr/search_results.rb
muck-solr-0.4.6 lib/acts_as_solr/search_results.rb
honkster-acts_as_solr-0.3.7 lib/acts_as_solr/search_results.rb
honkster-acts_as_solr-0.3.6 lib/acts_as_solr/search_results.rb