简体   繁体   English

MySQL数据库 最佳模式

[英]MySQL Database; best schema

I have a question about a database schema for a certain website where people can sell and buy stuff. 我有一个关于人们可以在其中买卖东西的网站的数据库架构的问题。

When someone adds an ad to the database, he will choose the category and fills out the filters that belong to the selected category, so anyone can easily find his ad by browsing to a category and choosing filters like: 当某人将广告添加到数据库时,他将选择类别并填写属于所选类别的过滤器,因此任何人都可以通过浏览至类别并选择以下过滤器来轻松找到其广告:

[bluetooth] yes [蓝牙]是的

[camera] 3 - 5 megapixels. [相机] 3-5百万像素。

Et cetera 等等

What is the best way to store these filters in the database? 将这些过滤器存储在数据库中的最佳方法是什么? This is what I have so far: 这是我到目前为止的内容:

Schema http://img98.imageshack.us/img98/5089/database2.jpg 架构http://img98.imageshack.us/img98/5089/database2.jpg

This is just an idea, but it will never send the ads back with value for filter "megapixels" between 3 and 5, since filter_value is of type VARCHAR . 这只是一个主意,但绝不会将过滤器“ megapixels”的值发送回3到5之间的广告,因为filter_value的类型为VARCHAR

I'd do with tables for: 我会用表做的:

  • ads 广告
  • filter names (category is just one of filters) 过滤器名称(类别只是过滤器之一)
  • filter values 过滤值
  • association between ad and filter values 广告和过滤器值之间的关联

Store it any way you like but for efficient querying based on these filters set up Solr and use faceted searching. 以您喜欢的任何方式存储它,但为了基于这些过滤器进行高效查询,请设置Solr并使用多面搜索。

The design works pretty fine according to me, I am curious as to why you have included an additional id field in the join table, eg between ads and categories. 根据我的说法,设计工作还不错,我很好奇您为什么在联接表中加入了一个额外的id字段,例如广告和类别之间。 I think you could do without them. 我想你可以不用他们。 The design on the whole is pretty good because it lets you make changes to the base tables eg ads later on. 总体而言,该设计非常好,因为它使您可以在以后更改基表,例如广告。

Another thing What is filter_value? 另一件事是filter_value? and why cant it go in the filters table? 为何不能将其放入过滤器表?

Have you considered an additional table, filter_value_list with columns id, filter_id, and value? 您是否考虑过另一个具有表ID,filter_id和value的表filter_value_list? This table would contain a list of VARCHAR answers that would be supplied to the user in the form of a drop down for each filter linked to the category of the ad that is being placed. 该表将包含一个VARCHAR答案列表,该列表将以下拉列表的形式提供给用户,每个下拉列表都链接到要放置的广告类别。

For the "Bluetooth" filter, the possible values would be "Yes" and "No". 对于“蓝牙”过滤器,可能的值为“是”和“否”。 For the "Camera" filter, the possible values might be "Less than 1 megapixel", "1 or 2 megapixels", "3 to 5 megapixels", "5 to 10 megapixels", "More than 10 megapixels" (we're planning for future technology here). 对于“相机”滤镜,可能的值可能是“小于1百万像素”,“ 1或2百万像素”,“ 3到5百万像素”,“ 5到10百万像素”,“超过10百万像素”(在这里规划未来的技术)。

The advantages: 优点:

  1. User selects, rather than types, their answer. 用户选择而不是键入答案。

  2. Each filter is guaranteed to be understood by your system. 保证您的系统可以理解每个过滤器。

  3. Consistency across all advertisements. 所有广告的一致性。

  4. The possible value list can also be used in an "add/remove filters" sidebar like you see on many sites these days. 可能的值列表也可以在“添加/删除过滤器”侧边栏中使用,就像这些天在许多网站上看到的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM