Delta indexing post update_all

74 views
Skip to first unread message

Sundar Rajamanickam

unread,
Jul 5, 2016, 9:16:32 AM7/5/16
to Thinking Sphinx
Hi

If I do the following, how will the documents be removed from core index ( because we do not invoke ThinkingSphinx::Deltas::DeleteJob ) ? Is there an impact with not removing the documents from core index ?

Article.where(<some_condition>).update_all("delta = 1")
ThinkingSphinx::Deltas::IndexJob.new("article_delta").perform


Also, if I only want to en-queue jobs in DJ queue post update_all, what should be done ?


Gem versions:

gem 'thinking-sphinx', '3.0.4'
gem 'ts-delayed-delta', '~> 2.0.2'

Pat Allan

unread,
Jul 23, 2016, 2:51:20 AM7/23/16
to thinkin...@googlegroups.com
Hi Sundar

Sorry for being so slow on responding to this.

Certainly, the code you’ve got there will not remove documents from the core index. What this means is that any queries that match old data in the core index will return results that you may not want. What you could do instead is the following:

  ids = Article.where(<some_condition>).pluck :id
  
  Article.where(:ids => ids).update_all :delta => true
  ThinkingSphinx::Deltas::IndexJob.new(‘article_delta’).perform
  
  indices = ThinkingSphinx::Configuration.instance.indices_for_references(:article)
  indices.reject { |index| index.delta? }.each do |index|
    ids.each do |id|
      ThinkingSphinx::Deltas::DeleteJob.new(
        index.name, index.document_id_for_key(id)
      ).perform
    end
  end

Note that this code should work with TS v3.0.4. A slightly simpler approach (which involves far fewer Sphinx queries) is available since v3.1.2:

  ids = Article.where(<some_condition>).pluck :id
  
  Article.where(:ids => ids).update_all :delta => true
  ThinkingSphinx::Deltas::IndexJob.new(‘article_delta’).perform
  
  indices = ThinkingSphinx::Configuration.instance.indices_for_references(:article)
  indices.reject { |index| index.delta? }.each do |index|
    ThinkingSphinx::Deletion.perform index, ids
  end

If you wanted to push this behaviour into Delayed Job instead, then I’d recommend creating a custom job class to do so (as the internals of ts-delayed-delta for deleting from the core index are written with single instances in mind).

Hope this helps!

— 
Pat

--
You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to thinking-sphi...@googlegroups.com.
To post to this group, send email to thinkin...@googlegroups.com.
Visit this group at https://groups.google.com/group/thinking-sphinx.
For more options, visit https://groups.google.com/d/optout.

Sundar Rajamanickam

unread,
Jul 23, 2016, 3:33:55 AM7/23/16
to thinkin...@googlegroups.com
Thanks Pat. This should help me.

--
You received this message because you are subscribed to a topic in the Google Groups "Thinking Sphinx" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/thinking-sphinx/8u3iS_wNfGA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to thinking-sphi...@googlegroups.com.

To post to this group, send email to thinkin...@googlegroups.com.
Visit this group at https://groups.google.com/group/thinking-sphinx.
For more options, visit https://groups.google.com/d/optout.



--

Sundar Rajamanickam  
Software Design Engineer, Chronus
+91 9566098418


    
Reply all
Reply to author
Forward
0 new messages