Getting "Error Code: 1191. Can't find FULLTEXT index matching the column list" when querying multiple columns with FULLTEXT indexes simultaneously

huangapple go评论58阅读模式
英文:

Getting "Error Code: 1191. Can't find FULLTEXT index matching the column list" when querying multiple columns with FULLTEXT indexes simultaneously

问题

在MySQL 8.0的InnoDB引擎中使用全文索引,你可以单独查询每个列并返回结果,例如:

SELECT *
FROM all_prod
WHERE MATCH (job_summary) AGAINST ('marketing');

SELECT *
FROM all_prod
WHERE MATCH (sub_role) AGAINST ('marketing');

SELECT *
FROM all_prod
WHERE MATCH (region) AGAINST ('marketing');

SELECT *
FROM all_prod
WHERE MATCH (job_title) AGAINST ('marketing');

SELECT *
FROM all_prod
WHERE MATCH (industry) AGAINST ('marketing');

SELECT *
FROM all_prod
WHERE MATCH (industry2) AGAINST ('marketing');

SELECT *
FROM all_prod
WHERE MATCH (company_industry) AGAINST ('marketing');

然而,当尝试运行类似这样的查询时:

SELECT *
FROM all_prod
WHERE MATCH (sub_role, region, job_title, job_summary, 
industry2, industry, company_industry) 
AGAINST ('+marketing' IN BOOLEAN MODE);

或者

SELECT *
FROM all_prod
WHERE location_continent = 'Europe'
  AND mobile IS NOT NULL 
  AND emails IS NOT NULL 
  AND phone_numbers IS NOT NULL
  AND MATCH (job_summary, sub_role, region, job_title, 
   industry, industry2, company_industry) 
   AGAINST ('marketing');

你会收到错误信息:

错误代码: 1191. 无法找到与列列表匹配的FULLTEXT索引

这是因为你在全文索引的MATCH函数中使用了多个列,但是MySQL的FULLTEXT索引只能在单个列上工作。你需要分别对每个列进行查询,然后将结果合并。希望这能帮到你。

英文:

Using MySQL 8.0, InnoDB Engine. I can query the columns and return results using the fulltext index on individual columns such as this:

SELECT *
FROM all_prod
WHERE MATCH (job_summary) AGAINST ('marketing');

SELECT *
FROM all_prod
WHERE MATCH (sub_role) AGAINST ('marketing');

SELECT *
FROM all_prod
WHERE MATCH (region) AGAINST ('marketing');

SELECT *
FROM all_prod
WHERE MATCH (job_title) AGAINST ('marketing');

SELECT *
FROM all_prod
WHERE MATCH (industry) AGAINST ('marketing');

SELECT *
FROM all_prod
WHERE MATCH (industry2) AGAINST ('marketing');

SELECT *
FROM all_prod
WHERE MATCH (company_industry) AGAINST ('marketing');

However, when trying to run something like this:

SELECT *
FROM all_prod
WHERE MATCH (sub_role, region, job_title, job_summary, 
industry2, industry, company_industry) 
AGAINST ('+marketing' IN BOOLEAN MODE);

or

SELECT *
FROM all_prod
WHERE location_continent = 'Europe'
  AND mobile IS NOT NULL 
  AND emails IS NOT NULL 
  AND phone_numbers IS NOT NULL
  AND MATCH (job_summary, sub_role, region, job_title, 
   industry, industry2, company_industry) 
   AGAINST ('marketing');

I receive the error

> Error Code: 1191. Can't find FULLTEXT index matching the column list

Can someone explain what I'm doing wrong? Do I need to query each column individually and then combine the results afterwards? Eventually this will be part of a search functionality in PHP, I'm just testing the SQL first to make sure it will work as intended..

I have run a TABLE OPTIMIZE statement already, to rebuild the indexes and make sure there wasn't an issue there..

答案1

得分: 1

MATCH() 函数的参数必须与您的全文索引定义中的列相同,并且顺序也必须相同。

看起来您已经为每个单独的列创建了七个个别的全文索引。

如果您希望一次针对所有列运行 MATCH(),您需要定义一个包含所有七列的索引,如下所示:

CREATE FULLTEXT INDEX all_prod_ft ON all_prod (
 sub_role, 
 region, 
 job_title, 
 job_summary, 
 industry2, 
 industry, 
 company_industry
);
英文:

The arguments to MATCH() must be the same columns as those in your fulltext index definition, and in the same order.

It sounds like you have created seven individual fulltext indexes, one for each single column.

If you want to run a MATCH() against all of the columns at once, you would need to define one index with all seven columns like the following:

CREATE FULLTEXT INDEX all_prod_ft ON all_prod (
 sub_role, 
 region, 
 job_title, 
 job_summary, 
 industry2, 
 industry, 
 company_industry
);

huangapple
  • 本文由 发表于 2023年3月10日 00:26:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/75687404.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定