Sha256: a633073bc1d9a7acd207675f85b42ff023fb19284364d71389363eeaac9a871b

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

class ThinkingSphinx::RealTime::Callbacks::RealTimeCallbacks <
  ThinkingSphinx::Callbacks

  callbacks :after_save

  def after_save
    return unless real_time_indices?

    real_time_indices.each do |index|
      columns, values = ['id'], [index.document_id_for_key(instance.id)]
      (index.fields + index.attributes).each do |property|
        columns << property.name
        values  << property.translate(instance)
      end

      sphinxql = Riddle::Query::Insert.new(index.name, columns, values).replace!
      connection.execute sphinxql.to_sql
    end
  end

  private

  def config
    ThinkingSphinx::Configuration.instance
  end

  def connection
    connection = ThinkingSphinx::Connection.new
  end

  def indices
    @indices ||= config.indices_for_references reference
  end

  def real_time_indices?
    real_time_indices.any?
  end

  def real_time_indices
    @real_time_indices ||= indices.select { |index|
      index.is_a? ThinkingSphinx::RealTime::Index
    }
  end

  def reference
    instance.class.name.underscore.to_sym
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thinking-sphinx-3.0.0.rc lib/thinking_sphinx/real_time/callbacks/real_time_callbacks.rb