I have the following models.
class Post < ActiveRecord::Base
has_many :timeline_items, :as=>:subject
define_index do
....?
end
end
class TimelineItem < ActiveRecord::Base
belongs_to :subject, :polymorphic=>true
belongs_to :actor, :polymorphic=>:true
end
I want to get all the posts belonging to specific actors with thinking-sphinx.
In ActiveRecord I would do like
Post.where('timeline_items.actor_type = "User" AND timeline_items.actor_id IN [1,2,3]).includes(:timeline_items)
My question is what indexes have to define and what query have to use to get the same results with thinking-sphinx?
Update
However I also need to filter the posts by different actor types like:
Post.where('timeline_items.actor_type = "Group" AND timeline_items.actor_id IN [1,2,3]).includes(:timeline_items)
Give the following a try:
And then for searching:
As detailed in the comments, if you need to filter on a specific class’s values in those polymorphic associations, then you’re going to need to create another association for just that class. This is because Sphinx has no concept of hashes/key-value pairs, and so can’t track which ids belongs to which classes.
Once you have that new association in place, then add an attribute for that much like above – perhaps like this: