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

> On 10 Sep 2016, at 12:51 AM, Pulkit Sharma <[email protected]> wrote:
> 
> 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
> 
> 
> -- 
> 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 [email protected] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> Visit this group at https://groups.google.com/group/thinking-sphinx 
> <https://groups.google.com/group/thinking-sphinx>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.


-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/thinking-sphinx.
For more options, visit https://groups.google.com/d/optout.

Reply via email to