php - laravel 相关文章 tags 查询 或者 sql 语句查询
怪我咯
怪我咯 2017-04-10 18:00:03
0
1
399

module

article
tag

每篇文章有很多 tag

想查询 某篇文章 最接近的前5篇相关文章 (tags 匹配的最多)

比如 id 为 1 的文章 tagsred,small,gala,zi

每篇文章的这么多 tags 该如何存储有利于查询更快 ,又该如何查询相关文章呢

怪我咯
怪我咯

走同样的路,发现不同的人生

Antworte allen(1)
刘奇

经常在逛论坛的时候,发现有浏览文章的相关文档推荐,但具体他们怎么实现不是很清楚。。
个人想法:
1、建立标签字典表tag
id name
1 red
2 small
...
2、建立文章标签映射表article_tag
id article_id tag_id
1 1 1
2 1 2
...
3、文章表关联映射表,获取所有文章标签匹配个数排序

select article_id,count(1) cnt
  from article_tag
  where tag_id in (select tag_id from article_tag where article_id=1) and article_id!=1
  group by article_id
  order by cnt desc
  limit 5
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!