Class: ThinkingSphinx::Deltas::DelayedDelta

Inherits:
DefaultDelta
  • Object
show all
Defined in:
lib/thinking_sphinx/deltas/delayed_delta.rb

Overview

Delayed Deltas for Thinking Sphinx, using Delayed Job.

This documentation is aimed at those reading the code. If you’re looking for a guide to Thinking Sphinx and/or deltas, I recommend you start with the Thinking Sphinx site instead - or the README for this library at the very least.

See Also:

Author:

  • Patrick Allan

Instance Method Summary collapse

Instance Method Details

#index(model, instance = nil) ⇒ Boolean

Adds a job to the queue for processing the given model’s delta index. A job for hiding the instance in the core index is also created, if an instance is provided.

Neither job will be queued if updates or deltas are disabled, or if the instance (when given) is not toggled to be in the delta index. The first two options are controlled via ThinkingSphinx.updates_enabled? and ThinkingSphinx.deltas_enabled?.

Parameters:

  • model (Class)

    the ActiveRecord model to index.

  • instance (ActiveRecord::Base) (defaults to: nil)

    the instance of the given model that has changed. Optional.

Returns:

  • (Boolean)

    true



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/thinking_sphinx/deltas/delayed_delta.rb', line 33

def index(model, instance = nil)
  return true if skip? instance
  
  ThinkingSphinx::Deltas::Job.enqueue(
    ThinkingSphinx::Deltas::DeltaJob.new(model.delta_index_names),
    ThinkingSphinx::Configuration.instance.delayed_job_priority
  )
  
  Delayed::Job.enqueue(
    ThinkingSphinx::Deltas::FlagAsDeletedJob.new(
      model.core_index_names, instance.sphinx_document_id
    ),
    ThinkingSphinx::Configuration.instance.delayed_job_priority
  ) if instance
  
  true
end