存储图像类别的最佳逻辑
我正在创建一个系统,用户可以选择四个选项的任意组合。
然后根据它们的精确组合显示结果。
例如,如果用户选择颜色、文本和徽标。 仅返回具有颜色、文本和徽标的结果。
另一方面,我正在创建最终将返回的结果的“模板”。 每个模板都将被指定为当用户选择与该模板相对应的组合时能够正确返回。
我的问题:
在后端对这些信息进行分类以便可以根据用户请求提取的最佳方法是什么?
例如,我有一个模板,可以是颜色和文本或颜色、文本和徽标。 我的猜测是将这两者分成一个系列,然后在进行组合时,查询将审查每个系列以查找匹配的组合; 如果为 true,则返回特定的组合变体。
你会采取不同的做法吗?
谢谢!
I am creating a system where a user can select any combination of four options.
Then results are displayed based on their exact combination.
For example, if a user chose color, text, and logo. Only results featuring color, text, and logo would return.
On the other side, I am creating "templates" that will eventually be the results returned. Each template will be earmarked to be able to return properly when a user selects a combination that corresponds with the template.
My Question :
What is the best way to categorize this information in the back-end so it can be pulled by the user requests?
For example, I have a template that can be color and text OR color, text, and logo. My guess is two group these two in a family, and then when a combination is made, a query reviews each family for a matching combo; if true, that specific combo variation is returned.
Would you do it any differently?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不应该对可用类别的数量进行硬编码(如果明天您需要另一个类别怎么办?)
...
这种方法的缺点是您必须有一个对应表(类别组合)。
You shoudn't hardcode the number of available categories (what if tomorrow you need another category?)
...
The downside of this approach is that you must have a correspondence table (categories-combinations).
这是一个相当复杂的问题描述。 在没有真实的东西可供查看的情况下,我在解析其中一些内容时遇到了一些麻烦 - 例如“当进行组合时”。 (它与存储图像有什么关系?你的模板是图像吗?)
也就是说......我想说最简单的方法是将你的搜索作为 Rails 任务而不是数据任务来处理。 只需设置您的模板模型所需的任何属性:
然后,在模型中,为各种选项设置命名范围:
然后您可以简单地将它们链接在一起以匹配用户在搜索中检查的任何内容,例如
Template.with_color。 with_text.with_logo
,您将获得命名范围过滤结束时剩余的内容。那有意义吗? 命名范围对于这类事情非常方便——如果您以前没有遇到过它们,您可能需要 Google 一下它们。
This is a fairly complicated problem description. I'm having a little trouble parsing some of it -- e.g. "when a combination is made" -- in the absence of a real thing to look at. (And what does it have to do with storing images? Are your templates images?)
That said... I'd say the simplest approach is to handle your searching as a Rails task rather than a data task. Just set whatever attributes you need for your Template model:
Then, in the model, set named scopes for the various options:
Then you can simply chain them together to match whatever the user checked in their search, e.g.
Template.with_color.with_text.with_logo
and you'll get whatever survives at the end of the named scope filtering.Does that make sense? Named scopes are very handy for this sort of thing -- you might want to Google on them if you haven't come across them before.