[英]Sphinx searcing related has_many with thinkingsphinx
Hypothetically, I have a Room model that belongs to a Building model. 假设,我有一个属于建筑模型的房间模型。 Buildings has a has_many relationship with categories.
建筑物与类别具有has_many关系。
I'm trying to figure out how to index the Room model so that a search for category_id = 1 will return any room, in any building that happens to have that category assigned to it. 我试图弄清楚如何为Room模型建立索引,以便对category_id = 1的搜索将返回恰好为其分配了该类别的任何建筑物中的任何房间。 Again, a building can have multiple categories.
同样,建筑物可以具有多个类别。
thanks! 谢谢!
Firstly, you'll want to set up your index something like the following in your Post model: 首先,您需要在Post模型中设置类似于以下内容的索引:
define_index do
# fields go here
# the important attribute for your filter:
has building.categories(:id), :as => :category_ids
end
As for searching: 至于搜索:
Room.search 'query', :with => {:category_ids => 1}
Let me know if this isn't quite what you're after. 让我知道这是否与您的要求不符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.