Class: XTF::Result::Element::Base
- Inherits:
-
Object
- Object
- XTF::Result::Element::Base
- Defined in:
- lib/xtf/result/element/base.rb
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
require ‘rubygems’ require ‘libxml_helper’ require ‘erb’ include ERB::Util include ExportableDocument.
-
#path ⇒ Object
readonly
require ‘rubygems’ require ‘libxml_helper’ require ‘erb’ include ERB::Util include ExportableDocument.
-
#query ⇒ Object
readonly
require ‘rubygems’ require ‘libxml_helper’ require ‘erb’ include ERB::Util include ExportableDocument.
-
#rank ⇒ Object
readonly
require ‘rubygems’ require ‘libxml_helper’ require ‘erb’ include ERB::Util include ExportableDocument.
-
#raw_path ⇒ Object
readonly
require ‘rubygems’ require ‘libxml_helper’ require ‘erb’ include ERB::Util include ExportableDocument.
-
#score ⇒ Object
readonly
require ‘rubygems’ require ‘libxml_helper’ require ‘erb’ include ERB::Util include ExportableDocument.
-
#total_hits ⇒ Object
readonly
require ‘rubygems’ require ‘libxml_helper’ require ‘erb’ include ERB::Util include ExportableDocument.
-
#xml ⇒ Object
readonly
require ‘rubygems’ require ‘libxml_helper’ require ‘erb’ include ERB::Util include ExportableDocument.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(xml, query_params = "") {|_self| ... } ⇒ Base
constructor
A new instance of Base.
- #parse_xml(xml, query) ⇒ Object
-
#query_with_all_snippets ⇒ Object
Converts
maxSnippetsto a value of -1 (all), so that proper hit counts are shown in the XTF-rendered document.
Constructor Details
#initialize(xml, query_params = "") {|_self| ... } ⇒ Base
Returns a new instance of Base.
25 26 27 28 29 30 |
# File 'lib/xtf/result/element/base.rb', line 25 def initialize(xml, query_params="") start = Time.now parse_xml(xml, query_params) yield self if block_given? # RAILS_DEFAULT_LOGGER.debug("~~~~~ #{self.class.name} initialized in #{Time.now - start} seconds.") end |
Instance Attribute Details
#doc ⇒ Object (readonly)
require ‘rubygems’
require 'libxml_helper'
require 'erb'
include ERB::Util
include ExportableDocument
9 10 11 |
# File 'lib/xtf/result/element/base.rb', line 9 def doc @doc end |
#path ⇒ Object (readonly)
require ‘rubygems’
require 'libxml_helper'
require 'erb'
include ERB::Util
include ExportableDocument
9 10 11 |
# File 'lib/xtf/result/element/base.rb', line 9 def path @path end |
#query ⇒ Object (readonly)
require ‘rubygems’
require 'libxml_helper'
require 'erb'
include ERB::Util
include ExportableDocument
9 10 11 |
# File 'lib/xtf/result/element/base.rb', line 9 def query @query end |
#rank ⇒ Object (readonly)
require ‘rubygems’
require 'libxml_helper'
require 'erb'
include ERB::Util
include ExportableDocument
9 10 11 |
# File 'lib/xtf/result/element/base.rb', line 9 def rank @rank end |
#raw_path ⇒ Object (readonly)
require ‘rubygems’
require 'libxml_helper'
require 'erb'
include ERB::Util
include ExportableDocument
9 10 11 |
# File 'lib/xtf/result/element/base.rb', line 9 def raw_path @raw_path end |
#score ⇒ Object (readonly)
require ‘rubygems’
require 'libxml_helper'
require 'erb'
include ERB::Util
include ExportableDocument
9 10 11 |
# File 'lib/xtf/result/element/base.rb', line 9 def score @score end |
#total_hits ⇒ Object (readonly)
require ‘rubygems’
require 'libxml_helper'
require 'erb'
include ERB::Util
include ExportableDocument
9 10 11 |
# File 'lib/xtf/result/element/base.rb', line 9 def total_hits @total_hits end |
#xml ⇒ Object (readonly)
require ‘rubygems’
require 'libxml_helper'
require 'erb'
include ERB::Util
include ExportableDocument
9 10 11 |
# File 'lib/xtf/result/element/base.rb', line 9 def xml @xml end |
Class Method Details
.create(xml, query_params = "") ⇒ Object
32 33 34 |
# File 'lib/xtf/result/element/base.rb', line 32 def self.create(xml, query_params="") new(xml.to_s, query_params) end |
Instance Method Details
#parse_xml(xml, query) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/xtf/result/element/base.rb', line 36 def parse_xml(xml, query) @xml = xml.to_s.gsub(/\s+/, " ").strip @query = query @doc = XML::Document.parse_string(xml).root doc_hit = @doc.at('//docHit') = doc_hit.at('//meta') @rank = doc_hit['rank'] @path = @raw_path = doc_hit['path'] @score = doc_hit['score'] # NOTE if there are totalHits, then use them, else use meta_hit_count. XTF gives a count for all hits when # there are totalHits, but none at all when only metadata hits. @meta_hit_count = doc_hit.search('//meta//hit').size rescue 0 @total_hits = doc_hit['totalHits'].to_i > 0 ? doc_hit['totalHits'] : @meta_hit_count.to_s end |
#query_with_all_snippets ⇒ Object
Converts maxSnippets to a value of -1 (all), so that proper hit counts are shown in the XTF-rendered document. An instance variable is lazily loaded.
21 22 23 |
# File 'lib/xtf/result/element/base.rb', line 21 def query_with_all_snippets self.query.gsub(/maxSnippets=("|')\d+("|')/, %Q{maxSnippets="-1"}) end |