Class: GSA::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/bcms_google_mini_search/gsa.rb

Overview

Represents a single result (aka Hit) from a GSA query. Defined by code.google.com/apis/searchappliance/documentation/46/xml_reference.html#results_xml_tag_r

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml_element = nil) ⇒ Result

Returns a new instance of Result.

Parameters:

  • xml_element (RXEML::Element) (defaults to: nil)

    The <R> result from GSA a search.



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/bcms_google_mini_search/gsa.rb', line 112

def initialize(xml_element = nil)
  return if xml_element == nil
  self.number = xml_element.attributes["N"]
  self.title = xml_element.elements["T"].try(:text)
  self.url = xml_element.elements["U"].try(:text)
  self.description = xml_element.elements["S"].try(:text)

  cache_element = xml_element.elements["HAS/C"]

  if cache_element
    self.size = cache_element.attributes["SZ"]
    self.cache_id = cache_element.attributes["CID"]
  else
    self.size = ""
    self.cache_id=""
  end

end

Instance Attribute Details

#cache_idObject

Returns the value of attribute cache_id.



109
110
111
# File 'lib/bcms_google_mini_search/gsa.rb', line 109

def cache_id
  @cache_id
end

#descriptionObject

Returns the value of attribute description.



109
110
111
# File 'lib/bcms_google_mini_search/gsa.rb', line 109

def description
  @description
end

#numberObject

Returns the value of attribute number.



109
110
111
# File 'lib/bcms_google_mini_search/gsa.rb', line 109

def number
  @number
end

#resultsObject

Returns the value of attribute results.



109
110
111
# File 'lib/bcms_google_mini_search/gsa.rb', line 109

def results
  @results
end

#sizeObject

Returns the value of attribute size.



109
110
111
# File 'lib/bcms_google_mini_search/gsa.rb', line 109

def size
  @size
end

#titleObject

Returns the value of attribute title.



109
110
111
# File 'lib/bcms_google_mini_search/gsa.rb', line 109

def title
  @title
end

#urlObject

Returns the value of attribute url.



109
110
111
# File 'lib/bcms_google_mini_search/gsa.rb', line 109

def url
  @url
end

Instance Method Details

#cached_document_paramObject

Returns the value for q if a user wants to request the cached version of this document.



132
133
134
135
136
137
138
# File 'lib/bcms_google_mini_search/gsa.rb', line 132

def cached_document_param
  param = "cache:#{cache_id}:#{url}"
  if results
    param += "+#{results.query}"
  end
  param
end

#cached_document_url(gsa_query) ⇒ Object



140
141
142
# File 'lib/bcms_google_mini_search/gsa.rb', line 140

def cached_document_url(gsa_query)
  SearchResult.query_url(cached_document_param, {:host=>gsa_query.engine.host, :collection=>gsa_query.collection, :front_end=>gsa_query.front_end, :as_xml=>false})
end