Class: Solr::Response::Xml

Inherits:
Base
  • Object
show all
Defined in:
lib/solr/response/xml.rb

Direct Known Subclasses

AddDocument, Commit, Delete, ModifyDocument, Ping

Instance Attribute Summary collapse

Attributes inherited from Base

#raw_response

Instance Method Summary collapse

Methods inherited from Base

make_response

Constructor Details

#initialize(xml) ⇒ Xml

Returns a new instance of Xml.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/solr/response/xml.rb', line 19

def initialize(xml)
  super
  # parse the xml
  @doc = REXML::Document.new(xml)

  # look for the result code and string 
  # <?xml version="1.0" encoding="UTF-8"?>
  # <response>
  # <lst name="responseHeader"><int name="status">0</int><int name="QTime">2</int></lst>
  # </response>
  result = REXML::XPath.first(@doc, './response/lst[@name="responseHeader"]/int[@name="status"]')
  if result
    @status_code =  result.text
    @status_message = result.text  # TODO: any need for a message?
  end
rescue REXML::ParseException => e
  raise Solr::Exception.new("invalid response xml: #{e}")
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



17
18
19
# File 'lib/solr/response/xml.rb', line 17

def doc
  @doc
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



17
18
19
# File 'lib/solr/response/xml.rb', line 17

def status_code
  @status_code
end

#status_messageObject (readonly)

Returns the value of attribute status_message.



17
18
19
# File 'lib/solr/response/xml.rb', line 17

def status_message
  @status_message
end

Instance Method Details

#ok?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/solr/response/xml.rb', line 38

def ok?
  return @status_code == '0'
end