Module: ThinkingSphinx::Deltas::DelayedDelta::Binary

Included in:
ThinkingSphinx::Deltas::DelayedDelta
Defined in:
lib/thinking_sphinx/deltas/delayed_delta.rb

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



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/thinking_sphinx/deltas/delayed_delta.rb', line 76

def index(model, instance = nil)
  return true if skip? instance

  self.class.enqueue_unless_duplicates(
    ThinkingSphinx::Deltas::DelayedDelta::DeltaJob.new(
      model.delta_index_names
    )
  )

  Delayed::Job.enqueue(
    ThinkingSphinx::Deltas::DelayedDelta::FlagAsDeletedJob.new(
      model.core_index_names, instance.sphinx_document_id
    ), self.class.job_options
  ) if instance

  true
end