MySQL FULLTEXT 来自多个表的分数

发布于 2024-10-09 07:40:59 字数 853 浏览 0 评论 0原文

我正在尝试搜索卡车维护记录的 MySQL 数据库。我正在搜索的表是 Maintenance、Truck 和 Maintenance_parts。我需要做什么才能从卡车和 Maintenance_Parts 表中获取全文分数以添加到维护表中的分数?

SELECT maintenance_id, some_id, type_code, service_date, mileage, mg_id, mg_type, comments, work_done,
    MATCH(comments, work_done) AGAINST( 'valve tire' ) AS score
    FROM maintenance
    WHERE  type_code = 'truck'
    AND some_id IN (
        SELECT truck_id FROM truck 
        WHERE MATCH( truck_number, make, model, engine, vin_number, transmission_number, comments) AGAINST( 'P' )
        OR truck_number LIKE '%P%'
    )
    AND maintenance_id IN( 
        SELECT maintenance_id FROM maintenance_parts WHERE MATCH( part_num, part_desc, part_ref) AGAINST( 'valve tire' )
    )
    OR MATCH(comments, work_done) AGAINST( 'valve tire' )
    AND status = 'A' ORDER BY score DESC LIMIT 0, 30

I am trying to search a MySQL Database of maintenance records for trucks. The tables I am searching are Maintenance, Truck, and maintenance_parts. What do I need to do to get the FULLTEXT score from the Truck and Maintenance_Parts tables to add to the score from the Maintenance Table?

SELECT maintenance_id, some_id, type_code, service_date, mileage, mg_id, mg_type, comments, work_done,
    MATCH(comments, work_done) AGAINST( 'valve tire' ) AS score
    FROM maintenance
    WHERE  type_code = 'truck'
    AND some_id IN (
        SELECT truck_id FROM truck 
        WHERE MATCH( truck_number, make, model, engine, vin_number, transmission_number, comments) AGAINST( 'P' )
        OR truck_number LIKE '%P%'
    )
    AND maintenance_id IN( 
        SELECT maintenance_id FROM maintenance_parts WHERE MATCH( part_num, part_desc, part_ref) AGAINST( 'valve tire' )
    )
    OR MATCH(comments, work_done) AGAINST( 'valve tire' )
    AND status = 'A' ORDER BY score DESC LIMIT 0, 30

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨与橙与城 2024-10-16 07:40:59

您必须重写查询以消除子查询,并使用连接来代替。一旦子查询的全文搜索移动到父查询,您应该能够在那里加入分数。

You'd have to rewrite the query to eliminate the subqueries, and do it with joins instead. Once the subqueries' fulltext searches are moved up to the parent query, you should be able to join the scores there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文