Class: ActsAsSolr::SearchResults

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_solr/search_results.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(solr_data = {}) ⇒ SearchResults

Returns a new instance of SearchResults.


30
31
32
# File 'lib/acts_as_solr/search_results.rb', line 30

def initialize(solr_data={})
  @solr_data = solr_data
end

Instance Method Details

#facetsObject

Returns the facets when doing a faceted search


47
48
49
# File 'lib/acts_as_solr/search_results.rb', line 47

def facets
  @solr_data[:facets]
end

#max_scoreObject Also known as: highest_score

Returns the highest score found. This method is also aliased as highest_score


53
54
55
# File 'lib/acts_as_solr/search_results.rb', line 53

def max_score
  @solr_data[:max_score]
end

#query_timeObject


57
58
59
# File 'lib/acts_as_solr/search_results.rb', line 57

def query_time
  @solr_data[:query_time]
end

#resultsObject Also known as: docs, records

Returns an array with the instances. This method is also aliased as docs and records


36
37
38
# File 'lib/acts_as_solr/search_results.rb', line 36

def results
  @solr_data[:docs]
end

#totalObject Also known as: num_found, total_hits

Returns the total records found. This method is also aliased as num_found and total_hits


42
43
44
# File 'lib/acts_as_solr/search_results.rb', line 42

def total
  @solr_data[:total]
end