Sha256: c15b43b024d9d0b7465dba48ab4f8b756ee7b52a5458e7a51a7da4588ba9ad4c

Contents?: true

Size: 1.3 KB

Versions: 17

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

class ThinkingSphinx::Commands::MergeAndUpdate < ThinkingSphinx::Commands::Base
  def call
    configuration.preload_indices
    configuration.render

    index_pairs.each do |(core_index, delta_index)|
      command :merge,
        :core_index  => core_index,
        :delta_index => delta_index,
        :filters     => {:sphinx_deleted => 0}

      core_index.model.where(:delta => true).update_all(:delta => false)
    end
  end

  private

  delegate :controller, :to => :configuration

  def core_indices
    indices.select { |index| !index.delta? }.select do |index|
      name_filters.empty? ||
      name_filters.include?(index.name.gsub(/_core$/, ''))
    end
  end

  def delta_for(core_index)
    name = core_index.name.gsub(/_core$/, "_delta")
    indices.detect { |index| index.name == name }
  end

  def index_pairs
    core_indices.collect { |core_index|
      [core_index, delta_for(core_index)]
    }
  end

  def indices
    @indices ||= configuration.indices.select { |index|
      index.type == "plain" && index.options[:delta_processor]
    }
  end

  def indices_exist?(*indices)
    indices.all? { |index| File.exist?("#{index.path}.spi") }
  end

  def name_filters
    @name_filters ||= options[:index_names] || []
  end

  def type
    'merging_and_updating'
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
thinking-sphinx-5.6.0 lib/thinking_sphinx/commands/merge_and_update.rb
thinking-sphinx-5.5.1 lib/thinking_sphinx/commands/merge_and_update.rb
thinking-sphinx-5.5.0 lib/thinking_sphinx/commands/merge_and_update.rb
thinking-sphinx-5.4.0 lib/thinking_sphinx/commands/merge_and_update.rb
thinking-sphinx-5.3.0 lib/thinking_sphinx/commands/merge_and_update.rb
thinking-sphinx-5.2.1 lib/thinking_sphinx/commands/merge_and_update.rb
thinking-sphinx-5.2.0 lib/thinking_sphinx/commands/merge_and_update.rb
thinking-sphinx-5.1.0 lib/thinking_sphinx/commands/merge_and_update.rb
thinking-sphinx-5.0.0 lib/thinking_sphinx/commands/merge_and_update.rb
thinking-sphinx-4.4.1 lib/thinking_sphinx/commands/merge_and_update.rb
thinking-sphinx-4.4.0 lib/thinking_sphinx/commands/merge_and_update.rb
thinking-sphinx-4.3.2 lib/thinking_sphinx/commands/merge_and_update.rb
thinking-sphinx-4.3.1 lib/thinking_sphinx/commands/merge_and_update.rb
thinking-sphinx-4.3.0 lib/thinking_sphinx/commands/merge_and_update.rb
thinking-sphinx-4.2.0 lib/thinking_sphinx/commands/merge_and_update.rb
thinking-sphinx-4.1.0 lib/thinking_sphinx/commands/merge_and_update.rb
thinking-sphinx-4.0.0 lib/thinking_sphinx/commands/merge_and_update.rb