Class: ThinkingSphinx::Deltas::DatetimeDelta
- Inherits:
-
DefaultDelta
- Object
- DefaultDelta
- ThinkingSphinx::Deltas::DatetimeDelta
- Defined in:
- lib/thinking_sphinx/deltas/datetime_delta.rb
Instance Attribute Summary collapse
-
#column ⇒ Object
Returns the value of attribute column.
-
#threshold ⇒ Object
Returns the value of attribute threshold.
Instance Method Summary collapse
- #clause(model, toggled) ⇒ Object
- #delayed_index(model) ⇒ Object
- #index(model, instance = nil) ⇒ Object
-
#initialize(index, options) ⇒ DatetimeDelta
constructor
A new instance of DatetimeDelta.
- #reset_query(model) ⇒ Object
- #toggle(instance) ⇒ Object
- #toggled(instance) ⇒ Object
Constructor Details
#initialize(index, options) ⇒ DatetimeDelta
Returns a new instance of DatetimeDelta.
6 7 8 9 10 |
# File 'lib/thinking_sphinx/deltas/datetime_delta.rb', line 6 def initialize(index, ) @index = index @column = .delete(:delta_column) || :updated_at @threshold = .delete(:threshold) || 1.day end |
Instance Attribute Details
#column ⇒ Object
Returns the value of attribute column.
4 5 6 |
# File 'lib/thinking_sphinx/deltas/datetime_delta.rb', line 4 def column @column end |
#threshold ⇒ Object
Returns the value of attribute threshold.
4 5 6 |
# File 'lib/thinking_sphinx/deltas/datetime_delta.rb', line 4 def threshold @threshold end |
Instance Method Details
#clause(model, toggled) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/thinking_sphinx/deltas/datetime_delta.rb', line 40 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 |
#delayed_index(model) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/thinking_sphinx/deltas/datetime_delta.rb', line 17 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 |
#index(model, instance = nil) ⇒ Object
12 13 14 15 |
# File 'lib/thinking_sphinx/deltas/datetime_delta.rb', line 12 def index(model, instance = nil) # do nothing true end |
#reset_query(model) ⇒ Object
36 37 38 |
# File 'lib/thinking_sphinx/deltas/datetime_delta.rb', line 36 def reset_query(model) nil end |
#toggle(instance) ⇒ Object
28 29 30 |
# File 'lib/thinking_sphinx/deltas/datetime_delta.rb', line 28 def toggle(instance) # do nothing end |
#toggled(instance) ⇒ Object
32 33 34 |
# File 'lib/thinking_sphinx/deltas/datetime_delta.rb', line 32 def toggled(instance) instance.send(@column) > @threshold.ago end |