Sphinx 使用 Thinkingsphinx 搜索相关的 has_many
假设,我有一个属于建筑模型的房间模型。 建筑物与类别有 has_many 关系。
我正在尝试弄清楚如何对 Room 模型进行索引,以便搜索category_id = 1 将返回任何恰好分配有该类别的建筑物中的任何房间。 同样,一座建筑物可以有多个类别。
谢谢!
Hypothetically, I have a Room model that belongs to a Building model. Buildings has a has_many relationship with categories.
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. Again, a building can have multiple categories.
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您需要在 Post 模型中设置如下所示的索引:
至于搜索:
如果这不完全是您想要的,请告诉我。
Firstly, you'll want to set up your index something like the following in your Post model:
As for searching:
Let me know if this isn't quite what you're after.