0

我有 3 个表,t1、t2 和 t3,如下所示:

t1
___
t1id
name
address
type

t2
___
t2id
title

t3
____
t3id
t1id
t2id

我有一个关于 t1 的全文索引,涵盖nameaddresstype

我必须做什么才能使以下查询起作用?只是添加全文索引是t2.title行不通的,对吗?

SELECT t1.id, t1.name,MATCH(t1.name,t1.address,t1.type,t2.title) AGAINST ('query') as rank 
FROM t1
LEFT OUTER JOIN t3 ON t1.t1id = t3.t1id
LEFT OUTER JOIN t2 ON t3.t2id = t2.t2id
WHERE MATCH(t1.name,t1.address,t1.type,t2.title) AGAINST('query' IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION) 
HAVING rank > 0.2 
ORDER BY rank DESC

http://sqlfiddle.com/#!2/a0a59/7

4

1 回答 1

1

全文限制中所述

MATCH()列列表必须与表的某些FULLTEXT索引定义中的列列表完全匹配,除非这MATCH()IN BOOLEAN MODE. 布尔模式搜索可以在非索引列上完成,尽管它们可能很慢。

您可以改为组合多个MATCH()表达式:

SELECT   t1.id, t1.name,
         MATCH(t1.name, t1.address, t1.type) AGAINST ('query')
       + MATCH(t2.title                    ) AGAINST ('query')
      AS rank
FROM     t1 LEFT JOIN t3 USING (t1id)
            LEFT JOIN t2 USING (t2id)
WHERE    MATCH(t1.name, t1.address, t1.type) AGAINST ('query')
       + MATCH(t2.title                    ) AGAINST ('query')
       > 0.2
ORDER BY rank DESC
于 2012-10-21T05:24:09.270 回答