Class: ThinkingSphinx::Deltas::FlagAsDeletedJob
- Inherits:
-
Object
- Object
- ThinkingSphinx::Deltas::FlagAsDeletedJob
- Defined in:
- lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb
Overview
A simple job for flagging a specified Sphinx document in a given index as ‘deleted’.
Instance Attribute Summary collapse
-
#document_id ⇒ Object
Returns the value of attribute document_id.
-
#indexes ⇒ Object
Returns the value of attribute indexes.
Instance Method Summary collapse
-
#initialize(indexes, document_id) ⇒ FlagAsDeletedJob
constructor
Initialises the object with an index name and document id.
-
#perform ⇒ Boolean
Updates the sphinx_deleted attribute for the given document, setting the value to 1 (true).
Constructor Details
#initialize(indexes, document_id) ⇒ FlagAsDeletedJob
Initialises the object with an index name and document id. Please note that the document id is Sphinx’s unique identifier, and will almost certainly not be the model instance’s primary key value.
14 15 16 |
# File 'lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb', line 14 def initialize(indexes, document_id) @indexes, @document_id = indexes, document_id end |
Instance Attribute Details
#document_id ⇒ Object
Returns the value of attribute document_id.
5 6 7 |
# File 'lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb', line 5 def document_id @document_id end |
#indexes ⇒ Object
Returns the value of attribute indexes.
5 6 7 |
# File 'lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb', line 5 def indexes @indexes end |
Instance Method Details
#perform ⇒ Boolean
Updates the sphinx_deleted attribute for the given document, setting the value to 1 (true). This is not a special attribute in Sphinx, but is used by Thinking Sphinx to ignore deleted values between full re-indexing. It’s particularly useful in this situation to avoid old values in the core index and just use the new values in the delta index as a reference point.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb', line 26 def perform config = ThinkingSphinx::Configuration.instance indexes.each do |index| config.client.update( index, ['sphinx_deleted'], {@document_id => [1]} ) if ThinkingSphinx.sphinx_running? && ThinkingSphinx.search_for_id(@document_id, index) end true end |