Class: ActiveDocument::SearchResults

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ActiveDocument/search_results.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(results) ⇒ SearchResults

Returns a new instance of SearchResults.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ActiveDocument/search_results.rb', line 24

def initialize(results)
  @results_document = Nokogiri::XML(results)
  @facets = Hash.new
  @results_document.xpath("/search:response/search:facet").each do |facet|
    name = facet.xpath("./@name").to_s
    detail = Hash.new
    @facets[name] = detail
    facet.xpath("search:facet-value").each do |facet_value|
      detail[facet_value.xpath("./@name").to_s] = facet_value.xpath("./@count").to_s
    end
  end
end

Instance Attribute Details

#facetsObject (readonly)

Returns the value of attribute facets.



22
23
24
# File 'lib/ActiveDocument/search_results.rb', line 22

def facets
  @facets
end

Instance Method Details

#[](index) ⇒ Object



78
79
80
# File 'lib/ActiveDocument/search_results.rb', line 78

def [](index)
  SearchResult.new(@results_document.xpath("/search:response/search:result")[index])
end

#each(&block) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/ActiveDocument/search_results.rb', line 69

def each(&block)
  nodeset = @results_document.xpath("/search:response/search:result")
  if nodeset.length == 1
    yield SearchResult.new(nodeset[0])
  else
    @results_document.xpath("/search:response/search:result").each {|node| yield SearchResult.new(node)}
  end
end

#facet_resolution_timeObject



61
62
63
# File 'lib/ActiveDocument/search_results.rb', line 61

def facet_resolution_time
  @results_document.xpath("/search:response/search:metrics/search:facet-resolution-time/text()").to_s
end

#lengthObject



82
83
84
# File 'lib/ActiveDocument/search_results.rb', line 82

def length
  @results_document.xpath("/search:response/search:result").length
end

#page_lengthObject



45
46
47
# File 'lib/ActiveDocument/search_results.rb', line 45

def page_length
  Integer(@results_document.xpath("/search:response/@page-length").to_s)
end

#query_resolution_timeObject



53
54
55
# File 'lib/ActiveDocument/search_results.rb', line 53

def query_resolution_time
  @results_document.xpath("/search:response/search:metrics/search:query-resolution-time/text()").to_s
end

#search_textObject



49
50
51
# File 'lib/ActiveDocument/search_results.rb', line 49

def search_text
  @results_document.xpath("/search:response/search:qtext/text()").to_s
end

#snippet_resolution_timeObject



57
58
59
# File 'lib/ActiveDocument/search_results.rb', line 57

def snippet_resolution_time
  @results_document.xpath("/search:response/search:metrics/search:snippet-resolution-time/text()").to_s
end

#startObject



41
42
43
# File 'lib/ActiveDocument/search_results.rb', line 41

def start
  Integer(@results_document.xpath("/search:response/@start").to_s)
end

#totalObject



37
38
39
# File 'lib/ActiveDocument/search_results.rb', line 37

def total
  Integer(@results_document.xpath("/search:response/@total").to_s)
end

#total_timeObject



65
66
67
# File 'lib/ActiveDocument/search_results.rb', line 65

def total_time
  @results_document.xpath("/search:response/search:metrics/search:total-time/text()").to_s
end