dongzi9196 2014-10-28 21:36
浏览 32

MySQL全文搜索无法正常工作

I have this table with song titles, artist etc.


| id | artist | title | search_tags |

if(isset($_POST["search_value"]) && $_POST["search_value"] != null) {
        $search_value = $db->mysqli->real_escape_string($_POST["search_value"]);

        //hiq apostrofet
        //hiq pikat
        $search = array("\'", ".", " ");
        $replace = array("", "", " +");
        $search_value = str_replace($search, $replace, $search_value);

        $query = "
            select * from `music` 
            where 
                match(`search_tags`) against ('+$search_value*' IN BOOLEAN MODE)
            order by views desc
            limit 1
        ";

        //+ vihet per t paren

        $run_query = $db->mysqli->query($query);
        $result = $run_query->fetch_assoc();

        if($run_query->num_rows > 0)
            echo json_encode($result);
    }

It works fine in most cases but it is not working for some others.

Two main problems are:

  1. If I have two songs with these search tags:

a) era isterfi money per money

b) era istrefi e dehun

and when I search using this query: era e dehun it shows me era istrefi money per money as a result. Why is this happening? Are single chars a problem?

And 2. If I have a song with search_tags: 23 miley cyrus and I use 23 as a search query it shows me no result. Everything work fine if I search Miley for ex.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题