按多态关联思维狮身人面像过滤
我有以下型号。
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
我想通过thinking-sphinx获取属于特定演员的所有帖子。
在 ActiveRecord
中,我会这样做
Post.where('timeline_items.actor_type = "User" AND slider_items.actor_id IN [1,2,3]).includes(:timeline_items)
我的问题是必须定义哪些索引以及必须使用哪些查询才能获得与 Thinking-sphinx 相同的结果?
更新 但是,我还需要按不同的演员类型过滤帖子,例如: Post.where('timeline_items.actor_type = "Group" AND slider_items.actor_id IN [1,2,3]).includes(:timeline_items)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试以下操作:
然后进行搜索:
如注释中所详述,如果您需要在这些多态关联中过滤特定类的值,那么您将需要为该类创建另一个关联。这是因为 Sphinx 没有哈希/键值对的概念,因此无法跟踪哪些 id 属于哪些类。
一旦你有了新的关联,然后为它添加一个属性,就像上面一样 - 也许像这样:
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: