Skip to content

Commit

Permalink
index with rt attach
Browse files Browse the repository at this point in the history
  • Loading branch information
bibendi committed Apr 10, 2013
1 parent f332430 commit 4c9de04
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions lib/sphinx/integration/sphinx_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,39 @@ def index(online = true)
# TODO: replace all Blocker.full_reindex
Redis::Mutex.with_lock(:full_reindex, :expire => 3.hours) do
if remote_sphinx?
run_command("#{Rails.root}/script/sphinx --reindex-offline") if !online
run_command("#{Rails.root}/script/sphinx --reindex-offline") unless online
run_command("#{Rails.root}/script/sphinx --reindex-online") if online
else
run_command "indexer --config #{config_file} --all" if !online
run_command "indexer --config #{config_file} --all" unless online
run_command "indexer --config #{config_file} --rotate --all" if online
end
end

attach_rt if online
end
alias_method :reindex, :index

# Заполнить rt индексы из дисковых индексов
def attach_rt
ThinkingSphinx.context.indexed_models.select(&:rt_indexed_by_sphinx?).each do |model|
model.sphinx_indexes.each do |index|
# атачим rt индексы
query = "TRUNCATE RTINDEX #{index.rt_name}; ATTACH INDEX #{index.core_name} TO RTINDEX #{index.rt_name};"
ThinkingSphinx.take_connection{ |c| c.execute(query) }

# после этого нужно накатить дельту на основной rt индекс
# просто за атачить её нельзя, смёрджить тоже нельзя, поэтому будем апдейтить по одной
until model.search_count(:index => index.delta_rt_name).zero? do
model.search(:index => index.delta_rt_name, :per_page => 500).each do |record|
record.transmitter_replace
query = Riddle::Query::Delete.new(index.delta_rt_name, record.sphinx_document_id)
ThinkingSphinx.take_connection{ |c| c.execute(query.to_sql) }
end
end
end
end
end

def configure
config = ThinkingSphinx::Configuration.instance
puts "Generating Configuration to #{config.config_file}"
Expand All @@ -84,6 +107,7 @@ def rebuild
stop if sphinx_running?
index(false)
start
attach_rt
end
end

Expand Down

0 comments on commit 4c9de04

Please sign in to comment.