Class: ActiveDocument::SearchResult

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

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ SearchResult

Returns a new instance of SearchResult.



23
24
25
# File 'lib/ActiveDocument/search_result.rb', line 23

def initialize(node)
  @node = node
end

Instance Method Details

#[](index) ⇒ Object



66
67
68
# File 'lib/ActiveDocument/search_result.rb', line 66

def [](index)
  SearchMatch.new(@node.xpath("./corona:result/corona:snippet/span")[index])
end

#confidenceObject

def score

Float(@node.xpath("./@score").to_s)

end



43
44
45
# File 'lib/ActiveDocument/search_result.rb', line 43

def confidence
  Float(@node.xpath("./corona:result/corona:confidence").text.to_s)
end

#each(&block) ⇒ Object

def fitness

Float(@node.xpath("./@fitness").to_s)

end



51
52
53
54
55
56
57
58
# File 'lib/ActiveDocument/search_result.rb', line 51

def each(&block)
  nodeset = @node.xpath("./corona:result/corona:snippet/span")
  if nodeset.length == 1
    yield SearchMatch.new(nodeset[0])
  else
    @node.xpath("./corona:result/corona:snippet/span").each { |node| yield SearchMatch.new(node) }
  end
end

#lengthObject



70
71
72
# File 'lib/ActiveDocument/search_result.rb', line 70

def length
  @node.xpath("./corona:result/corona:snippet/span").length
end

#realize(klass) ⇒ Object



74
75
76
# File 'lib/ActiveDocument/search_result.rb', line 74

def realize(klass)
  klass.load(uri)
end

#root_typeObject



60
61
62
63
64
# File 'lib/ActiveDocument/search_result.rb', line 60

def root_type
  full_path = @node.xpath("./corona:result/corona:snippet/span").xpath("./@path").to_s
  root = full_path.match(/^\/[[:alpha:]]*((:)[[:alpha:]]*)?/) # find the first :something/ which should indicate the root
  root.to_s.delete(":/") # remove the : and / to get the root element name
end

#uriObject

def index

Integer(@node.xpath("./@index").to_s)

end



31
32
33
# File 'lib/ActiveDocument/search_result.rb', line 31

def uri
  @node.xpath("./corona:result/corona:uri").text.to_s
end