Class: Solr::Response::Xml

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

Overview

The ASF licenses this file to You under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

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.



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

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.



14
15
16
# File 'lib/solr/response/xml.rb', line 14

def doc
  @doc
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



14
15
16
# File 'lib/solr/response/xml.rb', line 14

def status_code
  @status_code
end

#status_messageObject (readonly)

Returns the value of attribute status_message.



14
15
16
# File 'lib/solr/response/xml.rb', line 14

def status_message
  @status_message
end

Instance Method Details

#ok?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/solr/response/xml.rb', line 35

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