MySQL FULLTEXT 来自多个表的分数
我正在尝试搜索卡车维护记录的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须重写查询以消除子查询,并使用连接来代替。一旦子查询的全文搜索移动到父查询,您应该能够在那里加入分数。
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.