我不知道我做错了什么,但找不到我的陈述的解决方案。目前的陈述是:
SELECT tb1.RestaurantID, Title, City
FROM Restaurant AS tb1
LEFT JOIN RestaurantLunch AS tb2 ON tb1.RestaurantID = tb2.RestaurantID
WHERE (MATCH (tb1.Title, tb1.City) AGAINST ('+string1* +string2*' IN BOOLEAN MODE)) LIMIT 5;
当然我还想在其他表(tb2)中搜索字符串,并将我的陈述更改为:
SELECT tb1.RestaurantID, Title, City
FROM Restaurant AS tb1
LEFT JOIN RestaurantLunch AS tb2 ON tb1.RestaurantID = tb2.RestaurantID
WHERE (MATCH (tb1.Title, tb1.City, tb2.Text) AGAINST ('+string1* +string2*' IN BOOLEAN MODE)) LIMIT 5;
提交后我得到不同的结果,这根本不是逻辑。这是为什么?
答案 0 :(得分:0)
当您执行左连接并在右侧表格的某个部分(在您的情况下为tb2)中创建条件时,此左连接变为具有该条件的纯连接。这就是为什么你会得到不同的结果。
尝试这种方式:
SELECT tb1.RestaurantID, Title, City
FROM Restaurant AS tb1
LEFT JOIN RestaurantLunch AS tb2
ON tb1.RestaurantID = tb2.RestaurantID
AND (MATCH (tb2.Text)
AGAINST ('+string1* +string2*' IN BOOLEAN MODE))
WHERE (MATCH (tb1.Title, tb1.City)
AGAINST ('+string1* +string2*' IN BOOLEAN MODE)) LIMIT 5;
答案 1 :(得分:0)
InnoDB表不允许在同一个MATCH子句中搜索多个全文索引。因此,在向同一个MATCH子句添加更多字段时,可能会得到不同的结果。在这里,您的字段并不都属于同一个表,因此它们由不同的索引覆盖。
我认为您应该将搜索拆分为每个MATCH子句使用一个全文索引。你可以试试
SELECT
tb1.RestaurantID, Title, City
FROM Restaurant AS tb1
LEFT JOIN RestaurantLunch AS tb2 ON tb1.RestaurantID = tb2.RestaurantID
WHERE (MATCH (tb1.Title, tb1.City) AGAINST ('+string1* +string2*' IN BOOLEAN MODE))
OR (tb2.Text IS NOT NULL AND MATCH (tb2.Text) AGAINST ('+string1* +string2*' IN BOOLEAN MODE))
LIMIT 5;