0

对于like搜索,我会做-

select name,"term1" as searchterm from articles where name like "%term1%"
union
select name,"term2" as searchterm from articles where name like "%term2%"`

我如何使用OR全文搜索在搜索中获取特定结果?有没有办法做到这一点 -

SELECT name,searchterm FROM articles WHERE MATCH (name)
 AGAINST ('term1 term2' IN BOOLEAN MODE);
4

1 回答 1

1

试试这个(它在本地和它的工作上进行了测试):

SELECT
    tmp1.msg,
    tmp2.tag_name
FROM (
    SELECT 
        CONVERT(name USING utf8) as msg 
    FROM 
        `articles` 
    WHERE 
        MATCH(`name`) AGAINST ('term1 term2' IN BOOLEAN MODE)
) as tmp1
INNER JOIN (
    SELECT CONVERT('term1' USING utf8) as tag_name
    UNION
    SELECT CONVERT('term2' USING utf8) as tag_name      
) as tmp2
    ON tmp1.msg LIKE CONCAT('%',tmp2.tag_name,'%')
于 2013-05-21T14:02:21.163 回答