我有3个表,t1,t2和t3如下:
t1
___
t1id
name
address
type
t2
___
t2id
title
t3
____
t3id
t1id
t2id
我在t1上有name
,address
和type
的全文索引。
要使以下查询有效,我该怎么办?只是向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
答案 0 :(得分: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