关于博客系统中Tag功能在数据库中的设计

对于一个博客或者新闻发布系统,一般都需要为每个文章打上Tag。  
下面是一个简单的设计方案:

1. 文章表的基本结构
create table tb_article (  
    id uuid not null,  
    tags varchar(250) not null,   # 由逗号分隔的多个tags,在界面上显示,不需要查询关联表。  
    title varchar(250) not null,  
    content text not null,  
    primary key (id)  
)


2. Tag的关联表

create table tb_tags_rel (
    id uuid not null,
    tag varchar(50) not null,    # 单个tag
    tag_type enum not null,      # Tag分类:新闻/下载文档/...
    target_id uuid not null,     # 对应文章的ID
    primary key (id)
)

这个表存储每个tag管理的对应文章,主要用来根据Tag进行查找。

可以实现像 http://www.oschina.com/article/tag/java 这样的URL


3. Tag的统计表

create table tb_tags_stat (
    id uuid not null,
    tag varchar(50) not null,
    tag_type enum not null,
    tag_desc varchar(50) null,   # Tag 的描述
    tag_color varchar(10) null,  # Tag 显示的颜色
    target_count int not null,   # 某个分类下的tag对应的文章数量
    tag_hits int not null,       # 某个分类下的tag被点击的次数
    primary key (id)
    unique index (tag, tag_type)
)

这个表主要存储每个tag对应分类的统计信息。

可以列出每个分类下所有的tag,以及每个tag包含的文章数量。


当然,这里只是一个设计思路,欢迎大家讨论。

(全文完)

转载于:https://my.oschina.net/sub/blog/115698

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值