class Findex::DocumentDecorator
A decorator class to be used around Xapian::Documents
Constants
- DATE_FORMAT
- TIME_FORMAT
- VALUE_SLOTS
Attributes
xapian_document[R]
Public Class Methods
new(xapian_document, root_path, file = nil)
click to toggle source
Calls superclass method
# File lib/findex/document_decorator.rb, line 20 def initialize(xapian_document, root_path, file = nil) @xapian_document = xapian_document @root_path = root_path super(xapian_document) update_values_from(file) if file end
Public Instance Methods
actual_mtime()
click to toggle source
# File lib/findex/document_decorator.rb, line 40 def actual_mtime Time.at(full_path.mtime.to_i) end
add_value(slot, value)
click to toggle source
Calls superclass method
# File lib/findex/document_decorator.rb, line 79 def add_value(slot, value) return super if slot.is_a?(Integer) super(VALUE_SLOTS[slot], value) end
changed?()
click to toggle source
# File lib/findex/document_decorator.rb, line 66 def changed? actual_mtime > mtime end
date()
click to toggle source
# File lib/findex/document_decorator.rb, line 49 def date @date ||= Date.strptime(value(:date), DATE_FORMAT) end
date=(date)
click to toggle source
# File lib/findex/document_decorator.rb, line 53 def date=(date) add_value(:date, date.strftime(DATE_FORMAT)) @date = date end
deleted?()
click to toggle source
# File lib/findex/document_decorator.rb, line 62 def deleted? !exists? end
exists?()
click to toggle source
# File lib/findex/document_decorator.rb, line 58 def exists? full_path.exist? end
extension()
click to toggle source
# File lib/findex/document_decorator.rb, line 70 def extension path.extname[1..-1] end
full_path()
click to toggle source
# File lib/findex/document_decorator.rb, line 94 def full_path @root_path + path end
insert(db, term_generator)
click to toggle source
# File lib/findex/document_decorator.rb, line 89 def insert(db, term_generator) index(term_generator) db.add_document(xapian_document) end
mtime()
click to toggle source
# File lib/findex/document_decorator.rb, line 36 def mtime @mtime ||= Time.strptime(value(:mtime), TIME_FORMAT) end
mtime=(time)
click to toggle source
# File lib/findex/document_decorator.rb, line 44 def mtime=(time) add_value(:mtime, time.strftime(TIME_FORMAT)) @mtime = time end
path()
click to toggle source
# File lib/findex/document_decorator.rb, line 27 def path @path ||= value(:path) end
path=(path)
click to toggle source
# File lib/findex/document_decorator.rb, line 31 def path=(path) add_value(:path, path.to_s) @path = path end
update(db, term_generator)
click to toggle source
# File lib/findex/document_decorator.rb, line 84 def update(db, term_generator) index(term_generator) db.replace_document(docid, xapian_document) end
value(slot)
click to toggle source
Calls superclass method
# File lib/findex/document_decorator.rb, line 74 def value(slot) return super if slot.is_a?(Integer) super(VALUE_SLOTS[slot]).force_encoding('UTF-8') end
Private Instance Methods
index(term_generator)
click to toggle source
# File lib/findex/document_decorator.rb, line 100 def index(term_generator) update_values_from(full_path) clear_terms term_generator.document = xapian_document index_text(TermGeneratorDecorator.new(term_generator, self)) end
index_text(term_generator)
click to toggle source
# File lib/findex/document_decorator.rb, line 107 def index_text(term_generator) file_indexer = FileIndexer.new(full_path) term_generator[:path] = path file_indexer.index(term_generator) end
update_values_from(file)
click to toggle source
# File lib/findex/document_decorator.rb, line 113 def update_values_from(file) self.path = file.relative_path_from(@root_path) self.mtime = full_path.mtime self.date = mtime.to_date end