mysql [全文搜索] - 显示用于获取特定结果的搜索词

时间:2013-05-21 13:10:10

标签: mysql

对于我会做的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);

1 个答案:

答案 0 :(得分: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,'%')