dongtazu3080 2015-08-01 04:06 采纳率: 100%
浏览 29
已采纳

MySQL与JOIN对抗

I'm trying to build a related images section that uses image tags.

My DB Structure is pretty straight forward:

table: images          table: image2tag      table: tags     
|image_id|image_path|  |t2i_id|image_id|tag_id|  |tag_id|tag_name|

What I would like to do is find images that share a high relation to the current image based on the tags in both. From going through other posts I think I might need to use MATCH AGASINT, the values being compared are numeric IDs, but according to dev.mysql.com MATCH AGAINST is for comparing text strings, so I'm confused.

I've found examples on stackoverflow but none where joins are involved, could someone help me out with this. What I've tried so far:

$getRelated = $conn -> prepare("SELECT *, 
    MATCH(it.image_tag_id) AGAINST (?) AS score 
FROM images i 
    LEFT JOIN image2tag i2t
ON i.image_id = i2t.i2t_image_id
    LEFT JOIN image_tags it
ON i2t.i2t_tag_id = it.image_tag_id
    WHERE MATCH(it.image_tag_id) AGAINST (?)
    ORDER BY score DESC LIMIT 5");
        $getRelated -> bindParam(1, $tags, PDO::PARAM_STR);
        $getRelated -> bindParam(2, $tags, PDO::PARAM_STR);
        $getRelated -> execute();

I think I'm going about this the wrong way, any help would be appreciated.

  • 写回答

1条回答 默认 最新

  • dswu26846 2015-08-01 05:38
    关注

    It's a long time ago I used this.

    You need fhe following:

    • myisam
    • char, varchar or text datatype
    • full text index

    Numeric is not possible. See the official documentation: https://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html

    Maybe you can split the logic:

    • Do a full text search in your textual image tags
    • Do the joins with the image tags id from above
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路