Multiple Indexes in real time index

45 views
Skip to first unread message

Pulkit Sharma

unread,
Sep 9, 2016, 7:11:42 PM9/9/16
to Thinking Sphinx

Hi,


The machine I am running searchd on is a dual-core one, so I plan to create a distributed index for real-time indexes and set the appropriate value for ‘dist_threads’.


is this the correct way to create index so that I can utilise both the cores ?


ThinkingSphinx::Index.define :my_model, :name => ‘my_model_index0', :with => :real_time do

where 'id % 2 = 0'

indexes name

end


ThinkingSphinx::Index.define :my_model, :name => ‘my_model_index1', :with => :real_time do

where 'id % 2 = 1'

indexes name

end


The above generates two identical indexes(it seems the where condition is not being used, because this is not backed by ActiveRecord) , which is not what I want. I want to split the data in half among them. How to split the index conditionally ?


Thank You

Pat Allan

unread,
Sep 9, 2016, 7:48:56 PM9/9/16
to thinkin...@googlegroups.com
Hi Pulkit

You’re right, the where method only works in SQL-backed indices. There’s two steps to work around this for real-time indices (though please note I’ve not tested this!):

* Use scope in the index definitions to define the ActiveRecord scope used by ts:generate/ts:regenerate:

  scope { MyModel.where("id % 2 = 0")

* Have a custom callback to direct inserts/updates to the correct index (instead of the standard after_save approach covered in the documentation):

  after_save :update_sphinx

  def update_sphinx
    indices = ThinkingSphinx::Configuration.instance.indices_for_references(:my_model)
    if id % 2 = 0
      index = indices.detect { |index| index.name == ‘my_model_index0' }
    else
      index = indices.detect { |index| index.name == ‘my_model_index1' }
    end

    ThinkingSphinx::RealTime::Transcriber.new(index).copy self
  end

Give this a shot and let us know how it goes!

— 
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.

Reply all
Reply to author
Forward
0 new messages