Sha256: 298d7b35d1cd855227e20bba422416b399fb330e41b300150d17dc5ec699d34a

Contents?: true

Size: 1.85 KB

Versions: 22

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

22 entries across 22 versions & 5 rubygems

Version Path
skalee-thinking-sphinx-1.3.14.2 lib/thinking_sphinx/deltas/default_delta.rb
skalee-thinking-sphinx-1.3.14.1 lib/thinking_sphinx/deltas/default_delta.rb
hawkerb-thinking-sphinx-1.3.18 lib/thinking_sphinx/deltas/default_delta.rb
thinking-sphinx-1.3.16 lib/thinking_sphinx/deltas/default_delta.rb
hawkerb-thinking-sphinx-1.3.17 lib/thinking_sphinx/deltas/default_delta.rb
thinking-sphinx-1.3.15 lib/thinking_sphinx/deltas/default_delta.rb
hawkerb-thinking-sphinx-1.3.16 lib/thinking_sphinx/deltas/default_delta.rb
hawkerb-thinking-sphinx-1.3.15 lib/thinking_sphinx/deltas/default_delta.rb
hawkerb-thinking-sphinx-1.3.14 lib/thinking_sphinx/deltas/default_delta.rb
zipme-thinking-sphinx-1.3.14 lib/thinking_sphinx/deltas/default_delta.rb
thinking-sphinx-1.3.14 lib/thinking_sphinx/deltas/default_delta.rb
warp-thinking-sphinx-1.3.13 lib/thinking_sphinx/deltas/default_delta.rb
thinking-sphinx-1.3.13 lib/thinking_sphinx/deltas/default_delta.rb
thinking-sphinx-1.3.12 lib/thinking_sphinx/deltas/default_delta.rb
thinking-sphinx-1.3.11 lib/thinking_sphinx/deltas/default_delta.rb
warp-thinking-sphinx-1.3.11 lib/thinking_sphinx/deltas/default_delta.rb
warp-thinking-sphinx-1.3.10 lib/thinking_sphinx/deltas/default_delta.rb
thinking-sphinx-1.3.10 lib/thinking_sphinx/deltas/default_delta.rb
thinking-sphinx-1.3.9 lib/thinking_sphinx/deltas/default_delta.rb
thinking-sphinx-1.3.8 lib/thinking_sphinx/deltas/default_delta.rb