Class: Frett::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/frett/adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Adapter

Returns a new instance of Adapter.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/frett/adapter.rb', line 5

def initialize(options = {})
  new_index = options[:clean] || !Frett::Config.consider_mtime
  unless File.directory?(Frett::Config.index_path)
    new_index = true
    Dir.mkdir(Frett::Config.index_path)
  end
  @index = Ferret::Index::Index.new(:path => Frett::Config.index_path, :create => new_index)
  if new_index
    File.open(Frett::Config.mtime_path, "w") {}
    past = Time.local(1970,"jan",1,0,0,0)
    File.utime(past, past, Frett::Config.mtime_path)
    @index.field_infos.add_field :file,        :store => :yes, :index => :untokenized, :term_vector => :no
    @index.field_infos.add_field :content,     :store => :yes, :index => :yes
    @index.field_infos.add_field :line,        :store => :yes, :index => :yes,         :term_vector => :no
  end
end

Instance Method Details

#read {|@index| ... } ⇒ Object

Yields:

  • (@index)


28
29
30
# File 'lib/frett/adapter.rb', line 28

def read
  yield(@index)
end

#write {|@index| ... } ⇒ Object

Yields:

  • (@index)


22
23
24
25
26
# File 'lib/frett/adapter.rb', line 22

def write(&block)
  yield(@index)
  @index.optimize
  File.utime(Time.now, Time.now, Frett::Config.mtime_path)
end