具有多个模型的太阳黑子(在 Rails 中)
我有三个模型(User
、Tag
、Product
),它们交互 st User
有许多 Tags
和产品
。
出于搜索目的,我希望能够(使用一个搜索栏)搜索用户名、标签名称和产品描述。我还想在产品页面上搜索,但这仅与标签名称和产品描述相关。
以下是两个示例:
搜索:“Linus Torvalds”会返回三个模型中 Linus Torvalds 的所有实例,并且用户名的任何实例均位于较高位置。
搜索:年龄为“20-25”的“Linux”会返回名称/描述中包含“Linux”且属于该年龄范围的产品的所有用户实例,以及标签包含“Linux”和谁的用户有适合该年龄段的产品。请注意,如果搜索不包括年龄,那么它将默认搜索所有符合“Linux”部分的人,而不是没有。
我的问题是最好的方法是什么?我应该创建一个带有自己的控制器的搜索模型吗?我应该忽略它并将搜索部分包含在共享文件夹中吗?还有哪些其他方法?
非常感谢。
I have three models (User
, Tag
, Product
) and they interact s.t. User
has many Tags
and Products
.
For searching purposes, I would like to be able to search (with one search bar) on user names, tag names, and product descriptions. I would also like to search on product pages, but that is only relevant for tag names and product descriptions.
Here are two examples:
Search: "Linus Torvalds" returns all instances of Linus Torvalds in the three models with any instances of the user name being placed higher.
Search: "Linux" with age: "20-25" returns all instances of Users with Products that include "Linux" in their name/description and fall in that age range, as well as Users with tags that include "Linux" and who have Products that fall in that age range. Note that if the search didnt include the age, then it would default to all who fit the "Linux" part rather than none.
My question is what would be the best way of doing this? Should I create a search model with its own controller? Should I just ignore that and include a search partial in a shared folder? What other methods are there?
Thanks much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您正在执行任何复杂的条件,我喜欢搜索对象的想法。
但要使用太阳黑子搜索对象:
I like the idea of a Search object if you are doing any complicated conditions.
But to search across objects using Sunspot: