Sha256: 1e5ab3777558fd0469e5a196afb4b93783e1ee21d6b09893f65efcbd1f46d035

Contents?: true

Size: 1.45 KB

Versions: 20

Compression:

Stored size: 1.45 KB

Contents

module ThinkingSphinx
  module Deltas
    class DatetimeDelta < ThinkingSphinx::Deltas::DefaultDelta
      attr_accessor :column, :threshold
      
      def initialize(index, options)
        @index      = index
        @column     = options.delete(:delta_column) || :updated_at
        @threshold  = options.delete(:threshold)    || 1.day
      end
      
      def index(model, instance = nil)
        # do nothing
        true
      end
      
      def delayed_index(model)
        config = ThinkingSphinx::Configuration.instance
        rotate = ThinkingSphinx.sphinx_running? ? "--rotate" : ""
        
        output = `#{config.bin_path}indexer --config #{config.config_file} #{rotate} #{delta_index_name model}`
        output += `#{config.bin_path}indexer --config #{config.config_file} #{rotate} --merge #{core_index_name model} #{delta_index_name model} --merge-dst-range sphinx_deleted 0 0`
        puts output unless ThinkingSphinx.suppress_delta_output?
        
        true
      end
            
      def toggle(instance)
        # do nothing
      end
      
      def toggled(instance)
        instance.send(@column) > @threshold.ago
      end
      
      def reset_query(model)
        nil
      end
      
      def clause(model, toggled)
        if toggled
          "#{model.quoted_table_name}.#{@index.quote_column(@column.to_s)}" +
          " > #{adapter.time_difference(@threshold)}"
        else
          nil
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 6 rubygems

Version Path
DrMark-thinking-sphinx-1.1.6 lib/thinking_sphinx/deltas/datetime_delta.rb
dpickett-thinking-sphinx-1.1.12 lib/thinking_sphinx/deltas/datetime_delta.rb
dpickett-thinking-sphinx-1.1.4 lib/thinking_sphinx/deltas/datetime_delta.rb
freelancing-god-thinking-sphinx-1.1.10 lib/thinking_sphinx/deltas/datetime_delta.rb
freelancing-god-thinking-sphinx-1.1.11 lib/thinking_sphinx/deltas/datetime_delta.rb
freelancing-god-thinking-sphinx-1.1.12 lib/thinking_sphinx/deltas/datetime_delta.rb
freelancing-god-thinking-sphinx-1.1.3 lib/thinking_sphinx/deltas/datetime_delta.rb
freelancing-god-thinking-sphinx-1.1.4 lib/thinking_sphinx/deltas/datetime_delta.rb
freelancing-god-thinking-sphinx-1.1.5 lib/thinking_sphinx/deltas/datetime_delta.rb
freelancing-god-thinking-sphinx-1.1.6 lib/thinking_sphinx/deltas/datetime_delta.rb
freelancing-god-thinking-sphinx-1.1.7 lib/thinking_sphinx/deltas/datetime_delta.rb
freelancing-god-thinking-sphinx-1.1.8 lib/thinking_sphinx/deltas/datetime_delta.rb
freelancing-god-thinking-sphinx-1.1.9 lib/thinking_sphinx/deltas/datetime_delta.rb
lostboy-thinking-sphinx-1.1.5.1 lib/thinking_sphinx/deltas/datetime_delta.rb
lostboy-thinking-sphinx-1.1.5.2 lib/thinking_sphinx/deltas/datetime_delta.rb
lostboy-thinking-sphinx-1.1.5.3 lib/thinking_sphinx/deltas/datetime_delta.rb
lostboy-thinking-sphinx-1.1.5.4 lib/thinking_sphinx/deltas/datetime_delta.rb
lostboy-thinking-sphinx-1.1.5.5 lib/thinking_sphinx/deltas/datetime_delta.rb
pixeltrix-thinking-sphinx-1.1.5 lib/thinking_sphinx/deltas/datetime_delta.rb
sherpa99-thinking-sphinx-1.1.4 lib/thinking_sphinx/deltas/datetime_delta.rb