Class: Velocity::Instance::QueryResponse
- Inherits:
-
Object
- Object
- Velocity::Instance::QueryResponse
- Defined in:
- lib/acceleration/velocity.rb
Overview
QueryResponse wraps the XML output from a Query#search in an object which provides several convenience methods in addition to exposing the underlying XML document comprising the response.
Instance Attribute Summary collapse
-
#doc ⇒ Object
A handle on the XML document behind the response.
Instance Method Summary collapse
-
#documents ⇒ Object
Retrieve all documents from the query response.
-
#file ⇒ Object
Retrieve the file name of the browse file, a.k.a.
-
#initialize(doc) ⇒ QueryResponse
constructor
Create a new QueryResponse given the response XML from Velocity.
-
#results? ⇒ Boolean
Indicates if a query response actually contains documents.
Constructor Details
#initialize(doc) ⇒ QueryResponse
Create a new QueryResponse given the response XML from Velocity
398 399 400 |
# File 'lib/acceleration/velocity.rb', line 398 def initialize(doc) @doc = doc end |
Instance Attribute Details
#doc ⇒ Object
A handle on the XML document behind the response
393 394 395 |
# File 'lib/acceleration/velocity.rb', line 393 def doc @doc end |
Instance Method Details
#documents ⇒ Object
Retrieve all documents from the query response
412 413 414 415 416 |
# File 'lib/acceleration/velocity.rb', line 412 def documents doc.xpath('/query-results/list/document').collect do |d| Document.new d end end |
#file ⇒ Object
Retrieve the file name of the browse file, a.k.a. v:file
.
Pass this as the :file
option to Query#browse in order for that method to work properly.
423 424 425 |
# File 'lib/acceleration/velocity.rb', line 423 def file doc.xpath('/query-results/@file').first.value end |
#results? ⇒ Boolean
Indicates if a query response actually contains documents
405 406 407 |
# File 'lib/acceleration/velocity.rb', line 405 def results? !documents.empty? end |