简体   繁体   English

如何创建用于存储产品搜索过滤器的数据库模式

[英]how to create a database schema for storing product search filters

I am creating a simple product search webapp where user can filter the shopping products he has bookmarked on the basis of price, free delivery, name, shop etc. 我正在创建一个简单的产品搜索webapp,用户可以根据价格,免费送货,名称,商店等过滤他收藏的购物产品。

I am looking to implement custom search filters functionality where user can create a search filter, then save it for later use. 我希望实现自定义搜索过滤器功能,用户可以在其中创建搜索过滤器,然后保存以供以后使用。 Search filters are something like this: 搜索过滤器是这样的:

  • price is under $1000 价格低于1000美元
  • price is between $1000 to $2000 价格在1000美元到2000美元之间
  • free delivery available/not available 免费送货/不可用
  • shop is amazon/walmart/... 商店是亚马逊/沃尔玛/ ...
  • name contains "christmas" 名字包含“圣诞节”

Can somebody give me an idea of the database schema for storing such search filters in database. 有人可以让我了解用于在数据库中存储此类搜索过滤器的数据库模式。 Should I store the mysql clauses in database like "WHERE price < 1000", "WHERE free_delivery=1"... or may be create fields like this.. 我应该将mysql子句存储在数据库中,如“WHERE price <1000”,“WHERE free_delivery = 1”......或者可以创建这样的字段。

  • field (price, name, free_delivery) 字段(价格,名称,free_delivery)
  • value (1000) 价值(1000)
  • expr (less than, greater than) expr(小于,大于)
  • between (1000) 之间(1000)
  • and (2000) 和(2000)
  • contains 包含

You shouldn't store SQL clauses in the database. 您不应该在数据库中存储SQL子句。 I would recommend you do something like this: 我建议你做这样的事情:

CREATE TABLE store (
id INT NOT NULL PRIMARY KEY,
name VARCHAR(100)
);

Example rows: (1, "Amazon"), (2, "Walmart"), ... 示例行:(1,“亚马逊”),(2,“沃尔玛”),...

CREATE TABLE search_filter (
id INT NOT NULL PRIMARY KEY,
user_id INT NOT NULL,
name VARCHAR(100),
price_min INT,
price_max INT,
store_id INT,
has_free_delivery BOOLEAN,
keyword VARCHAR(50),
FOREIGN KEY (user_id) REFERENCES user(id),
FOREIGN KEY (store_id) REFERENCES store(id)
);

Example row: (1, 43, "amazon christmas", 1000, 1999, 1, True, "christmas") 示例行:(1,43,“amazon christmas”,1000,1999,1,True,“christmas”)

The above example would save a filter called "amazon christmas" associated with user 43. It specifies that the user wishes to look for products with price ranging from $1000 to $1999 at Walmart, with free delivery, and containing the keyword "christmas." 以上示例将保存与用户43相关联的称为“亚马逊圣诞节”的过滤器。它指定用户希望在沃尔玛寻找价格从1000美元到1999美元的产品,免费送货,并且包含关键字“圣诞节”。

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

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