Class: Median::Primo::SearchResult

Inherits:
Object
  • Object
show all
Includes:
XmlSupport
Defined in:
lib/median/primo/search_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml, search_request) ⇒ SearchResult

Returns a new instance of SearchResult.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/median/primo/search_result.rb', line 8

def initialize(xml, search_request)
  raise "XML result required. Given parameter was nil." unless xml.present?
  raise "Request required. Given parameter was nil."    unless search_request.present?

  xml = Nokogiri::XML(xml) if xml.is_a?(String)
  xml.remove_namespaces!
  super(xml)

  @xml            = xml
  @records        = xml.xpath("//DOCSET/DOC").collect       { |xml| Median::Primo::Record.new(xml) }
  @facets         = xml.xpath("//FACETLIST//FACET").collect { |xml| Median::Primo::Facet.new(xml)  }
  @search_request = search_request
end

Instance Attribute Details

#facetsObject

Returns the value of attribute facets.



22
23
24
# File 'lib/median/primo/search_result.rb', line 22

def facets
  @facets
end

#recordsObject

Returns the value of attribute records.



22
23
24
# File 'lib/median/primo/search_result.rb', line 22

def records
  @records
end

#search_requestObject

Returns the value of attribute search_request.



22
23
24
# File 'lib/median/primo/search_result.rb', line 22

def search_request
  @search_request
end

Instance Method Details

#has_next_page?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/median/primo/search_result.rb', line 32

def has_next_page?
  search_request.page < number_of_pages
end

#has_previous_page?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/median/primo/search_result.rb', line 36

def has_previous_page?
  search_request.page > 1
end

#next_pageObject



40
41
42
# File 'lib/median/primo/search_result.rb', line 40

def next_page
  has_next_page? ? search_request.page + 1 : number_of_pages
end

#number_of_pagesObject



28
29
30
# File 'lib/median/primo/search_result.rb', line 28

def number_of_pages
  (total_hits / search_request.page_size) + 1
end

#previous_pageObject



44
45
46
# File 'lib/median/primo/search_result.rb', line 44

def previous_page
  has_previous_page? ? search_request.page - 1 : 1
end

#to_xmlObject



24
25
26
# File 'lib/median/primo/search_result.rb', line 24

def to_xml
  @xml
end