Class: SimpleSolrClient::Response::QueryResponse
- Inherits:
-
GenericResponse
- Object
- GenericResponse
- SimpleSolrClient::Response::QueryResponse
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/simple_solr_client/response/query_response.rb
Instance Attribute Summary collapse
-
#docs ⇒ Object
readonly
Returns the value of attribute docs.
-
#first_index ⇒ Object
readonly
Returns the value of attribute first_index.
-
#num_found ⇒ Object
readonly
Returns the value of attribute num_found.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #each_with_rank ⇒ Object
-
#empty? ⇒ Boolean
True if there are no documents.
-
#initialize(solr_response) ⇒ QueryResponse
constructor
A new instance of QueryResponse.
- #last_index ⇒ Object
- #rank(id) ⇒ Object
- #score(id) ⇒ Object
Methods inherited from GenericResponse
Constructor Details
#initialize(solr_response) ⇒ QueryResponse
Returns a new instance of QueryResponse.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/simple_solr_client/response/query_response.rb', line 13 def initialize(solr_response) super resp = @solr_response['response'] @num_found = resp['numFound'] @first_index = resp['start'] + 1 @docs = [] @indexed_docs = {} resp['docs'].each_with_index do |d, i| doc_rank = i + @first_index doc = SimpleSolrClient::Response::Document.new(d) doc.rank = doc_rank @docs << doc @indexed_docs[doc.id] = doc end end |
Instance Attribute Details
#docs ⇒ Object (readonly)
Returns the value of attribute docs.
8 9 10 |
# File 'lib/simple_solr_client/response/query_response.rb', line 8 def docs @docs end |
#first_index ⇒ Object (readonly)
Returns the value of attribute first_index.
8 9 10 |
# File 'lib/simple_solr_client/response/query_response.rb', line 8 def first_index @first_index end |
#num_found ⇒ Object (readonly)
Returns the value of attribute num_found.
8 9 10 |
# File 'lib/simple_solr_client/response/query_response.rb', line 8 def num_found @num_found end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
8 9 10 |
# File 'lib/simple_solr_client/response/query_response.rb', line 8 def page @page end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
8 9 10 |
# File 'lib/simple_solr_client/response/query_response.rb', line 8 def params @params end |
Instance Method Details
#each_with_rank ⇒ Object
48 49 50 51 |
# File 'lib/simple_solr_client/response/query_response.rb', line 48 def each_with_rank return self.enum_for(:each_with_rank) unless block_given? @docs.each { |x| yield x, x.rank } end |
#empty? ⇒ Boolean
Returns True if there are no documents.
43 44 45 |
# File 'lib/simple_solr_client/response/query_response.rb', line 43 def empty? @docs.empty? end |
#last_index ⇒ Object
30 31 32 |
# File 'lib/simple_solr_client/response/query_response.rb', line 30 def last_index @first_index + @num_found end |
#rank(id) ⇒ Object
34 35 36 |
# File 'lib/simple_solr_client/response/query_response.rb', line 34 def rank(id) @indexed_docs[id.to_s].rank end |
#score(id) ⇒ Object
38 39 40 |
# File 'lib/simple_solr_client/response/query_response.rb', line 38 def score(id) @indexed_docs[id.to_s].score end |