Class: ActsAsFerret::RdigAdapter::Indexer

Inherits:
Object
  • Object
show all
Includes:
MonitorMixin
Defined in:
lib/acts_as_ferret/rdig_adapter.rb

Overview

Indexer class to replace RDig’s original indexer

Instance Method Summary collapse

Constructor Details

#initialize(batch_size, model_class, &block) ⇒ Indexer

Returns a new instance of Indexer.



26
27
28
29
30
31
32
33
# File 'lib/acts_as_ferret/rdig_adapter.rb', line 26

def initialize(batch_size, model_class, &block)
  @batch_size = batch_size
  @model_class = model_class
  @documents = []
  @offset = 0
  @block = block
  super()
end

Instance Method Details

#add(doc) ⇒ Object Also known as: <<



35
36
37
38
39
40
# File 'lib/acts_as_ferret/rdig_adapter.rb', line 35

def add(doc)
  synchronize do
    @documents << @model_class.new(doc.uri.to_s, doc)
    process_batch if @documents.size >= @batch_size
  end
end

#closeObject



43
44
45
46
47
# File 'lib/acts_as_ferret/rdig_adapter.rb', line 43

def close
  synchronize do
    process_batch
  end
end