Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

finished insert batch

  • Loading branch information...
commit 435b1091c9e5923f5fc97b2014f27a5b71701778 1 parent cd8ea89
@loniszczuk loniszczuk authored
View
6 lib/thinkingtank/init.rb
@@ -62,13 +62,13 @@ def update_index
it = ThinkingTank::Configuration.instance.client
idx_obj = self.to_indexable_obj
- it.document(idx_obj[:docid]).add(idx_obj[:fields])
+ it.document(idx_obj['docid']).add(idx_obj['fields'])
end
def to_indexable_obj
idx_obj = {}
- idx_obj[:docid] = self.class.name + ' ' + self.id.to_s
+ idx_obj['docid'] = self.class.name + ' ' + self.id.to_s
fields = {}
self.class.thinkingtank_builder.index_fields.each do |field|
@@ -78,7 +78,7 @@ def to_indexable_obj
fields[:__any] = fields.values.join " . "
fields[:__type] = self.class.name
- idx_obj[:fields] = fields
+ idx_obj['fields'] = fields
return idx_obj
end
View
15 lib/thinkingtank/tasks.rb
@@ -73,17 +73,28 @@ def reindex_models
def reindex(klass, batch = false)
it = ThinkingTank::Configuration.instance.client
docs = []
+ count = 0
+ puts "Indexing #{klass.name}:"
klass.find(:all).each do |obj|
- puts "re-indexing #{obj.class.name}:#{obj.id}"
docs << obj.to_indexable_obj
if docs.size >= 20
+ doc_names = docs.map { |doc| doc['docid'] }
+ puts doc_names .join(',')
it.batch_insert docs
+ count += docs.size
docs = []
end
end
- it.batch_insert docs
+ if docs.size > 0
+ doc_names = docs.map { |doc| doc['docid'] }
+ puts doc_names .join(',')
+ count += docs.size
+ it.batch_insert docs
+ end
+
+ puts "#{klass.name}s indexed : #{count}"
end
namespace :indextank do
View
4 thinkingtank.gemspec
@@ -2,7 +2,7 @@ require 'date'
Gem::Specification.new do |s|
s.name = %q{thinkingtank}
- s.version = "0.0.9"
+ s.version = "0.0.10"
s.date = Date.today.strftime("%Y-%m-%d")
s.authors = ["Flaptor"]
s.email = %q{indextank@flaptor.com}
@@ -11,5 +11,5 @@ Gem::Specification.new do |s|
s.description = %q{ActiveRecord extension that allows to define models that should be indexed in an existing IndexTank index.
It supports a very similar syntax to ThinkingSphinx allowing to easily port an existing project.}
s.files = Dir.glob("lib/**/*.rb") << 'README.rdoc'
- s.add_dependency "indextank", ">= 1.0.7"
+ s.add_dependency "indextank", ">= 1.0.8.1"
end
Please sign in to comment.
Something went wrong with that request. Please try again.