相关性查询似乎并未选择所有具有LIKE选择的记录

时间:2018-07-14 12:03:35

标签: mysql having relevance

通过此相关性查询,我试图通过查询tags中的部分“计算”来选择/查找标签tagarticles“计算思想”。id 16,但是似乎找不到多个标签。一旦我搜索“ almere”,它就会给出所需的文章结果(articleid 16和15)

SELECT s.seoUrl, a.*,
        (
            (
            if (t.tag LIKE '%computational%',7,0)
            )+
            (
            if (a.title LIKE '%computational%',5,0)
            )+
            (
            if (a.shortDescription LIKE '%computational%',4,0) 
            )+
            (
            if (a.content LIKE '%computational%',3,0)
            )+
            (
            if (m.name LIKE '%computational%',2,0)
            )+
            (
            if (s.seoUrl LIKE '%computational%',1,0)
            )
        ) as relevance
        FROM articles a
        LEFT JOIN article_tag at ON at.articleId = a.contentId
        LEFT JOIN seoUrls s ON s.contentId = a.contentId
        LEFT JOIN tags t ON at.tagId = t.contentId
        LEFT JOIN article_category ac ON ac.articleId = a.contentId
        LEFT JOIN menu m ON m.contentId = ac.categoryParentId
        WHERE a.published = 'on'
        GROUP BY a.contentId
        HAVING relevance > 0
        ORDER BY relevance DESC, a.views DESC

我认为我在选择标签时在左连接处犯了一个大错误,但我似乎找不到解决办法,有什么主意吗?

提琴: http://sqlfiddle.com/#!9/7a9d0f9/1

0 个答案:

没有答案