简体   繁体   English

为什么我的MySQL MATCH()AGAINST()查询因LEFT JOIN数据库中的列而失败?

[英]Why does my MySQL MATCH() AGAINST() query fail with columns from LEFT JOIN'd databases?

I've got a MySQL query somewhat like the following: 我有一个类似于以下内容的MySQL查询:

SELECT * 
FROM products 
LEFT JOIN descriptions ON products.DescriptionID = descriptions.ID 
WHERE MATCH (name, overview, specs) AGAINST ('ram');

All columns I'm trying to search with MATCH() AGAINST() are FULLTEXT, but I get the following error when testing in phpMyAdmin: 我试图使用MATCH() AGAINST()搜索的所有列都是FULLTEXT,但是在phpMyAdmin中进行测试时出现以下错误:

#1210 - Incorrect arguments to MATCH

If I only MATCH one column it doesn't error and works correctly, but as soon as I try to MATCH multiple columns it fails with this error. 如果我只MATCH一列,则不会出错并且可以正常工作,但是,当我尝试MATCH多列时,它会因该错误而失败。 I'm running MySQL 5.0.45 and the MySQL 5.0 Full-Text Search Functions documentation implies I can do this. 我正在运行MySQL 5.0.45,而MySQL 5.0全文搜索功能文档暗示我可以做到这一点。

Is it because of the LEFT JOIN ? 是因为有LEFT JOIN吗? Do I need to OR together a bunch of MATCH() AGAINST() function calls? 我是否需要对一堆MATCH() AGAINST()函数进行OR

Update @Zak: I can't post the table creation statements, but I can say that in this example the columns are as follows: products.name , descriptions.overview , descriptions.specs . @Zak更新:我无法发布表创建语句,但是我可以说在此示例中,列如下: products.namedescriptions.overviewdescriptions.specs If I specify them in full table.column format, it doesn't change the behavior. 如果我以完整的table.column格式指定它们,则不会更改行为。

However, if I lose products.name from the MATCH() I get the following error: 但是,如果我输了products.nameMATCH()我收到以下错误:

#1191 - Can't find FULLTEXT index matching the column list

But, both descriptions.overview and descriptions.specs are FULLTEXT. 但是, descriptions.overviewdescriptions.specs均为FULLTEXT。

The arguments to MATCH() must be the same columns in your FULLTEXT index definition. MATCH()的参数必须与FULLTEXT索引定义中的列相同。 They must be the same in number as well as position. 它们的数量和位置必须相同。

Also, since you can't make an index with multiple columns from different tables, you can't match against columns from different tables in a single MATCH() call. 同样,由于您无法使用来自不同表的多个列创建索引,因此无法在单个MATCH()调用中与来自不同表的列进行MATCH()

If you want to search text columns from different tables, you'll have to create a FULLTEXT index in each table, and then search each index with a separate MATCH() call. 如果要搜索不同表中的文本列,则必须在每个表中创建FULLTEXT索引,然后使用单独的MATCH()调用搜索每个索引。 Use OR expressions to combine the results. 使用OR表达式合并结果。

I've run into that same problem. 我遇到了同样的问题。 The thing is that you can't match columns from different tables so you have to split the query. 事实是,您无法匹配不同表中的列,因此必须拆分查询。

Try something like this (edited to match columns and tables): 尝试这样的事情(编辑以匹配列和表):

SELECT p.name, d.overview, d.specs
FROM products AS p 
LEFT JOIN descriptions AS d ON p.DescriptionID = d.ID 
WHERE MATCH (p.name) AGAINST ('ram')
OR MATCH (d.overview, d.specs) AGAINST ('ram');

Hope it helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM