Class: MongoidXapian::Trail

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
lib/mongoid-xapian/trail.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.index_all!Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/mongoid-xapian/trail.rb', line 16

def self.index_all!
  FileUtils.mkpath("#{Bundler.root}/xapian")
  while self.count != 0
    # get the documents in group of 100 so the cursor doesn't expire.
    self.order_by(:created_at.asc).limit(100).each do |trail|
      begin
        trail.index!
      rescue Exception => e
        puts "[mongoid-xapit] Something went wrong while indexing document #{trail.doc_type} #{trail.doc_id}: #{e.to_s} (#{e.class})"
        puts "#{e.backtrace[0,10].join("\n\t")}"
        trail.delete
      end
    end
  end
end

Instance Method Details

#index!Object



11
12
13
14
# File 'lib/mongoid-xapian/trail.rb', line 11

def index!
  self.send(:"#{action}_document")
  self.delete
end

#indexableObject



32
33
34
# File 'lib/mongoid-xapian/trail.rb', line 32

def indexable
  @indexable ||= indexable_class.where(:_id => self.doc_id).first
end

#indexable_classObject



36
37
38
# File 'lib/mongoid-xapian/trail.rb', line 36

def indexable_class
  self.doc_type.constantize
end