class Xapian::Indexer::Resource
Represents a resource that will be indexed
Attributes
body[R]
header[R]
metadata[R]
name[R]
status[R]
Public Class Methods
new(name, controller, values = {})
click to toggle source
# File lib/xapian/indexer/resource.rb, line 92 def initialize(name, controller, values = {}) @name = name @controller = controller @fetched_on = values[:fetched_on] @status = values[:status] @header = values[:header] @body = values[:body] @metadata = values[:metadata] end
Public Instance Methods
content()
click to toggle source
The data that will be indexed
# File lib/xapian/indexer/resource.rb, line 121 def content [@metadata[:content] || @body, @metadata[:title], @metadata[:description], @metadata[:keywords]].compact.join(" ") end
content?()
click to toggle source
# File lib/xapian/indexer/resource.rb, line 162 def content? @body != nil end
fetch!()
click to toggle source
# File lib/xapian/indexer/resource.rb, line 148 def fetch! @controller.load(self) do |status, header, body, metadata| @fetched_on = Time.now @status = status @header = header @body = body @metadata = metadata end end
fetched?()
click to toggle source
# File lib/xapian/indexer/resource.rb, line 158 def fetched? @fetched_on != nil end
fresh?(at = Time.now)
click to toggle source
# File lib/xapian/indexer/resource.rb, line 129 def fresh?(at = Time.now) cache_control = @header['cache-control'] || "" fetched_age = @header['age'] || "" max_age = 3600 if cache_control.match(/max-age=([0-9]+)/) max_age = $1.to_i if fetched_age.match(/([0-9]+)/) max_age -= $1.to_i end end age = at - @fetched_on # If the page is younger than the max_age the page can be considered fresh. return age < max_age end
links()
click to toggle source
# File lib/xapian/indexer/resource.rb, line 125 def links @metadata[:links] if @metadata end
name_digest()
click to toggle source
# File lib/xapian/indexer/resource.rb, line 166 def name_digest "Q" + Digest::MD5.hexdigest(@name) end
to_hash()
click to toggle source
# File lib/xapian/indexer/resource.rb, line 109 def to_hash { :fetched_on => @fetched_on, :name => @name, :status => @status, :header => @header, :body => @body, :metadata => @metadata } end