Class: SimpleSolrClient::Response::QueryResponse

Inherits:
GenericResponse show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/simple_solr_client/response/query_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from GenericResponse

#status

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

#docsObject (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_indexObject (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_foundObject (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

#pageObject (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

#paramsObject (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_rankObject



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.

Returns:

  • (Boolean)

    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_indexObject



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