Class: Solrizer::Rabbit::ShardedIndexer

Inherits:
Object
  • Object
show all
Defined in:
lib/solrizer-rabbit/sharded_indexer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeShardedIndexer

Returns a new instance of ShardedIndexer.



4
5
6
7
8
9
10
# File 'lib/solrizer-rabbit/sharded_indexer.rb', line 4

def initialize
  self.shards = YAML.load_file(Rails.root + 'config/shards.yml')[Rails.env]
  @buffers = []
  shards.each do |conf|
    @buffers << DTU::BufferedIndexer.new(RSolr.connect(:url=>conf))
  end
end

Instance Attribute Details

#shardsObject

Returns the value of attribute shards.



3
4
5
# File 'lib/solrizer-rabbit/sharded_indexer.rb', line 3

def shards
  @shards
end

Instance Method Details

#add(doc) ⇒ Object



12
13
14
# File 'lib/solrizer-rabbit/sharded_indexer.rb', line 12

def add(doc)
  buffer(doc['id']).add(doc)
end

#buffer(id) ⇒ Object



24
25
26
27
28
# File 'lib/solrizer-rabbit/sharded_indexer.rb', line 24

def buffer(id)
  raise "No id" unless id
  n = Digest::MD5.hexdigest(id.to_s).hex % @buffers.count
  @buffers[n]
end

#delete(doc) ⇒ Object



16
17
18
# File 'lib/solrizer-rabbit/sharded_indexer.rb', line 16

def delete(doc)
  buffer(doc['id']).delete_by_id(doc['id'])
end

#flush(commit = false) ⇒ Object



20
21
22
# File 'lib/solrizer-rabbit/sharded_indexer.rb', line 20

def flush(commit = false)
  @buffers.each {|b| b.flush(commit)}
end