Hi Murray

> On 28 March 2010 05:43, Pat Allan <[email protected]> wrote:
>> What you've found is just how Sphinx works - when using filters across 
>> multiple indexes, any without the needed attributes are ignored.
>> 
> What I'm seeing feels like the opposite: the attributes that weren't present 
> in both indexes were ignored, rather than ignoring the index that didn't 
> include those attributes.

Ah, this is because both super and subclass indexes share document ids (ie: the 
indexes refer to the same documents, as they are indeed the same records). And 
so I guess because that document exists in some places without the attribute, 
it's considered not to have it at all.

>  And I feel it makes sense for a superclass's index to be included when 
> searching on subclasses.
>> 
>> 
>> That said, I think there's a neater way of working around this... just use 
>> :index in your search:
>> 
>>  School.search 'High',
>>    :with => {:teacher_ids => User.first.id},
>>    :index => 'school_core'
>> 
>> I guess it's a bit brittle, but probably better than monkeypatching TS.
>> 
> That is a bit nicer than monkey patching TS, although I'm not too keen on 
> having to specify the index explicitly every time I want to search School's 
> using it's index.  To that end, I wonder, would it be worth having an option 
> to define_index to mark an index as "exclusive" for that model, and not to 
> automatically include superclass indexes in searches?  If the expected 
> behaviour with attributes is as I'm observing then subclass indexes that add 
> extra attributes become unusable (without doing as you suggest and explicitly 
> telling the search to only use this index for every query).

Sure, something like this definitely sounds useful... maybe:

  set_property :default => true

Within the subclass index definition?

> I'm happy to work up a patch if you think there's merit in it.

That'd be fantastic. I'm (obviously) a little short of time to spend on TS at 
the moment, so it'd be great if you could work out a patch for this.

Cheers

-- 
Pat

>  
> Cheers,
> 
> Murray
> 
>> Cheers
>> 
>> --
>> Pat
>> 
> On 24/03/2010, at 2:01 AM, Muz wrote:
> 
> > Hi all,
> >
> > I've got an STI model setup to have separate indexes as follows:
> >
> > class Organization < ActiveRecord::Base
> >  define_index do
> >    indexes name
> >  end
> > end
> >
> > class School < Organization
> >  has_many :teachers_join
> >  has_many :teachers :through => :teachers_join
> >
> >  define_index do
> >    indexes name
> >    has teachers(:user_id), :as => :teacher_ids, :type => :integer
> >  end
> > end
> >
> > What isn't working for me is doing something like:
> >
> > School.search('High', :with => {:teacher_ids => User.first.id)})
> >
> > I'd expect that to find me all the Schools belonging to User.first
> > (assuming they were a teacher) with "High" in the name.  However,
> > regardless of what I put in as a :with (or :without) it just returns
> > me all the schools with "High" in the name.
> >
> > I did some digging it looks like School.search_indexes has both
> > school_core and organization_core in it, and it seems that
> > because :teacher_ids isn't an attribute on organization_core, those
> > filters just get ignored.  If I make it so that the sphinx_indexes of
> > School only contains the School index by adding:
> >
> > class << self
> >  def add_sphinx_index(index)
> >    super if index.model == self
> >  end
> > end
> >
> > to my School class then it works as I expected it to.
> >
> > So my questions are:
> >
> > * Anyone else had this sort of problem?
> > * Would this have any other side-affects?
> > * Should I wrap this up in a more sensible patch?
> >
> > Cheers
> >
> > Murray
> >
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Thinking Sphinx" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to 
> > [email protected].
> > For more options, visit this group at 
> > http://groups.google.com/group/thinking-sphinx?hl=en.
> >
> 
> --
> You received this message because you are subscribed to the Google Groups 
> "Thinking Sphinx" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/thinking-sphinx?hl=en.
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Thinking Sphinx" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/thinking-sphinx?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en.

Reply via email to