【问题标题】:Mysql, similar topicsmysql,类似的话题
【发布时间】:2011-07-22 14:53:59
【问题描述】:

大家好!

我有 3 张桌子:

topics
(id*, title, body) 

tags
(id*,name)

topic_tags
(topic_id,tag_id)

每个主题都有一些标签。我想找到与另一个“最相关”的主题,仅基于标签(而不是基于主题的标题和正文)。

如果 2 个主题有更常见的标签,则它们的相关性更高。我想以某种方式通过相似性(=​​ 常见标签的数量)对结果进行排序。

你有什么建议?

【问题讨论】:

    标签: mysql tags similarity


    【解决方案1】:
    SELECT  tr.*
    FROM    topic t
    JOIN    topic_tag tt
    ON      tt.topic_id = t.id
    JOIN    topic_tag ttr
    ON      ttr.tag_id = tt.tag_id
    JOIN    topic tr
    ON      tr.id = ttr.topic_id
    WHERE   t.id = $topicid
    GROUP BY
            tr.id
    ORDER BY
            COUNT(*) DESC
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-26
      • 2011-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多