Class: ActiveDocument::SearchResult
- Inherits:
-
Object
- Object
- ActiveDocument::SearchResult
- Includes:
- Enumerable
- Defined in:
- lib/ActiveDocument/search_result.rb
Instance Method Summary collapse
- #[](index) ⇒ Object
- #confidence ⇒ Object
- #each(&block) ⇒ Object
- #fitness ⇒ Object
- #index ⇒ Object
-
#initialize(node) ⇒ SearchResult
constructor
A new instance of SearchResult.
- #length ⇒ Object
- #path ⇒ Object
- #realize(klass) ⇒ Object
- #root_type ⇒ Object
- #score ⇒ Object
- #uri ⇒ Object
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 |
#confidence ⇒ Object
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 |
#fitness ⇒ Object
47 48 49 |
# File 'lib/ActiveDocument/search_result.rb', line 47 def fitness Float(@node.xpath("./@fitness").to_s) end |
#index ⇒ Object
27 28 29 |
# File 'lib/ActiveDocument/search_result.rb', line 27 def index Integer(@node.xpath("./@index").to_s) end |
#length ⇒ Object
70 71 72 |
# File 'lib/ActiveDocument/search_result.rb', line 70 def length @node.xpath("./search:snippet/search:match").length end |
#path ⇒ Object
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_type ⇒ Object
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 |
#score ⇒ Object
39 40 41 |
# File 'lib/ActiveDocument/search_result.rb', line 39 def score Float(@node.xpath("./@score").to_s) end |
#uri ⇒ Object
31 32 33 |
# File 'lib/ActiveDocument/search_result.rb', line 31 def uri @node.xpath("./@uri").to_s end |