Sha256: 50284a77b4834a2759fd8bbdbc2bdc5a5341ec3a576bf59bffb1bcdfe9c71227

Contents?: true

Size: 1.5 KB

Versions: 36

Compression:

Stored size: 1.5 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}#{config.indexer_binary_name} --config #{config.config_file} #{rotate} #{delta_index_name model}`
        output += `#{config.bin_path}#{config.indexer_binary_name} --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}.#{model.connection.quote_column_name(@column.to_s)}" +
          " > #{adapter.time_difference(@threshold)}"
        else
          nil
        end
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 12 rubygems

Version Path
freelancing-god-thinking-sphinx-1.2.7 lib/thinking_sphinx/deltas/datetime_delta.rb
freelancing-god-thinking-sphinx-1.2.8 lib/thinking_sphinx/deltas/datetime_delta.rb
freelancing-god-thinking-sphinx-1.2.9 lib/thinking_sphinx/deltas/datetime_delta.rb
hariton-thinking-sphinx-1.2.11.2 lib/thinking_sphinx/deltas/datetime_delta.rb
hariton-thinking-sphinx-1.2.11 lib/thinking_sphinx/deltas/datetime_delta.rb
hariton-thinking-sphinx-1.2.7.0 lib/thinking_sphinx/deltas/datetime_delta.rb
hariton-thinking-sphinx-1.2.7.1 lib/thinking_sphinx/deltas/datetime_delta.rb
pixeltrix-thinking-sphinx-1.2.1 lib/thinking_sphinx/deltas/datetime_delta.rb
thinking-sphinx-099-1.2.13 lib/thinking_sphinx/deltas/datetime_delta.rb
thinking-sphinx-1.2.13 lib/thinking_sphinx/deltas/datetime_delta.rb
moneypools-thinking-sphinx-1.2.13 lib/thinking_sphinx/deltas/datetime_delta.rb
moneypools-thinking-sphinx-1.2.12 lib/thinking_sphinx/deltas/datetime_delta.rb
moneypools-thinking-sphinx-1.2.11 lib/thinking_sphinx/deltas/datetime_delta.rb
warp-thinking-sphinx-1.2.12 lib/thinking_sphinx/deltas/datetime_delta.rb
thinking-sphinx-099-1.2.12 lib/thinking_sphinx/deltas/datetime_delta.rb
thinking-sphinx-1.2.12 lib/thinking_sphinx/deltas/datetime_delta.rb