Any way to achieve fulltext-like search on InnoDB

后端 未结 3 935
广开言路
广开言路 2020-11-29 12:37

I have a very simple query:

SELECT ... WHERE row LIKE \'%some%\' OR row LIKE \'%search%\' OR  row LIKE \'%string%\'

to search for som

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 13:39

    Using PHP to construct the query. This is an horrible hack. Once seen, it can't be unseen...

    $words=dict($userQuery);
    $numwords = sizeof($words);
    $innerquery="";
    for($i=0;$i<$numwords;$i++) {
        $words[$i] = mysql_real_escape_string($words[$i]);
        if($i>0) $innerquery .= " AND ";
        $innerquery .= "
            (
                field1 LIKE \"%$words[$i]%\" OR
                field2 LIKE \"%$words[$i]%\" OR
                field3 LIKE \"%$words[$i]%\" OR
                field4 LIKE \"%$words[$i]%\"
            )
        ";
    }
    
    
    SELECT fields FROM table WHERE $innerquery AND whatever;
    

    dict is a dictionary function

提交回复
热议问题