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("./search:snippet/search:match")[index])
end

#confidenceObject



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

def confidence
  Float(@node.xpath("./@confidence").to_s)
end

#each(&block) ⇒ Object



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

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

#fitnessObject



47
48
49
# File 'lib/ActiveDocument/search_result.rb', line 47

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

#indexObject



27
28
29
# File 'lib/ActiveDocument/search_result.rb', line 27

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

#lengthObject



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

def length
  @node.xpath("./search:snippet/search:match").length
end

#pathObject



35
36
37
# File 'lib/ActiveDocument/search_result.rb', line 35

def path
  @node.xpath("./@path").to_s
end

#realize(klass) ⇒ Object



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

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("./search:snippet/search:match")[0].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

#scoreObject



39
40
41
# File 'lib/ActiveDocument/search_result.rb', line 39

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

#uriObject



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

def uri
  @node.xpath("./@uri").to_s
end