2013-05-21 71 views
0

對於like搜索顯示搜索詞,我會做 -的MySQL [全文檢索] - 用來獲取特定結果

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

試試這個(它是在本地和其工作測試):

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,'%')