Sha256: a12d2fc0a59b47f3c6ce6cd12b053e17d2ca792851ddb173aec47f11eccccc8d

Contents?: true

Size: 1.85 KB

Versions: 9

Compression:

Stored size: 1.85 KB

Contents

module ThinkingSphinx
  module Deltas
    class DefaultDelta
      attr_accessor :column
      
      def initialize(index, options)
        @index  = index
        @column = options.delete(:delta_column) || :delta
      end
      
      def index(model, instance = nil)
        return true unless ThinkingSphinx.updates_enabled? &&
          ThinkingSphinx.deltas_enabled?
        return true if instance && !toggled(instance)
        
        update_delta_indexes model
        delete_from_core     model, instance if instance
        
        true
      end
      
      def toggle(instance)
        instance.delta = true
      end
      
      def toggled(instance)
        instance.delta
      end
      
      def reset_query(model)
        "UPDATE #{model.quoted_table_name} SET " +
        "#{model.connection.quote_column_name(@column.to_s)} = #{adapter.boolean(false)} " +
        "WHERE #{model.connection.quote_column_name(@column.to_s)} = #{adapter.boolean(true)}"
      end
      
      def clause(model, toggled)
        "#{model.quoted_table_name}.#{model.connection.quote_column_name(@column.to_s)}" +
        " = #{adapter.boolean(toggled)}"
      end
      
      private
      
      def update_delta_indexes(model)
        config = ThinkingSphinx::Configuration.instance
        rotate = ThinkingSphinx.sphinx_running? ? "--rotate" : ""
        
        output = `#{config.bin_path}#{config.indexer_binary_name} --config "#{config.config_file}" #{rotate} #{model.delta_index_names.join(' ')}`
        puts(output) unless ThinkingSphinx.suppress_delta_output?
      end
      
      def delete_from_core(model, instance)
        model.core_index_names.each do |index_name|
          model.delete_in_index index_name, instance.sphinx_document_id
        end
      end
      
      def adapter
        @adapter = @index.model.sphinx_database_adapter
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
thinking-sphinx-1.4.1 lib/thinking_sphinx/deltas/default_delta.rb
thinking-sphinx-2.0.1 lib/thinking_sphinx/deltas/default_delta.rb
thinking-sphinx-2.0.0 lib/thinking_sphinx/deltas/default_delta.rb
thinking-sphinx-1.4.0 lib/thinking_sphinx/deltas/default_delta.rb
thorsson_thinking-sphinx-2.0 lib/thinking_sphinx/deltas/default_delta.rb
angelf-thinking-sphinx-1.3.18 lib/thinking_sphinx/deltas/default_delta.rb
thinking-sphinx-1.3.20 lib/thinking_sphinx/deltas/default_delta.rb
thinking-sphinx-2.0.0.rc2 lib/thinking_sphinx/deltas/default_delta.rb
thinking-sphinx-1.3.19 lib/thinking_sphinx/deltas/default_delta.rb