【问题标题】:Relevance calculation with Match ... Against in JOIN queries (MySQL)在 JOIN 查询中使用 Match 进行相关性计算...反对 (MySQL)
【发布时间】:2019-01-29 04:39:00
【问题描述】:

我正在尝试使用以下 JOIN 查询获取相关搜索结果:

SELECT 
    `products`.`id`,
    `brands`.`name` AS `brand`,
    `products`.`name` AS `productname`,
    MATCH (`brands`.`name`) AGAINST ('somebrand someproduct' ) AS brandname_relevance
FROM
    `brands`
        INNER JOIN
    `products` ON `products`.`brand_id` = `brands`.`id`
WHERE
    MATCH (`products`.`name`) AGAINST ('somebrand someproduct' ) AS /* AS is highlighted as 'not valid input at this point' */ product_relevance
ORDER BY (brandname_relevance + product_relevance) DESC

但是,正如在代码中指出的那样,MySQL Workbench 在此上下文中将“AS”突出显示为无效。查询失败。

两个表中的引擎都是 InnoDB,但是 MySQL 服务器版本高于 5.6,并且为 brands.nameproducts.name 启用了 FULLTEXT 索引。请解释一下这里有什么问题。

【问题讨论】:

    标签: mysql join relevance match-against


    【解决方案1】:

    这是在 where 子句中 - 将它与您选择的其他字段一起向上移动。

    SELECT 
        `products`.`id`,
        `brands`.`name` AS `brand`,
        `products`.`name` AS `productname`,
        MATCH (`brands`.`name`) AGAINST ('somebrand someproduct' ) AS brandname_relevance,
        MATCH (`products`.`name`) AGAINST ('somebrand someproduct' ) AS product_relevance
    FROM
        `brands`
            INNER JOIN
        `products` ON `products`.`brand_id` = `brands`.`id`
    ORDER BY (brandname_relevance + product_relevance) DESC
    

    【讨论】:

    • 太棒了,非常感谢!
    猜你喜欢
    • 2019-04-24
    • 2020-09-27
    • 1970-01-01
    • 2012-01-06
    • 2017-10-22
    • 2010-10-06
    • 1970-01-01
    • 2018-05-26
    • 1970-01-01
    相关资源
    最近更新 更多