Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
614 views
in Technique[技术] by (71.8m points)

mysql - Multiple columns in MATCH AGAINST

I'm trying to get results from this query

SELECT ID FROM table1 WHERE MATCH(column1, column2) AGAINST ('text')

But I get this error #1191 - Can't find FULLTEXT index matching the column list

When I put only one column in MATCH it is working, two or more columns within MATCH doesn't work. I've seen people are doing it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The columns named inside MATCH() must be the same columns defined previously for a FULLTEXT index. That is, the set of columns must be the same in your index as in your call to MATCH().

So to search two columns, you must define a FULLTEXT index on the same two columns, in the same order.


The following is okay:

ALTER TABLE tabl1 ADD FULLTEXT INDEX (column1, column2);

SELECT ID FROM table1 WHERE MATCH(column1, column2) AGAINST ('text')

The following is wrong because the MATCH() references two columns but the index is defined for only one column.

ALTER TABLE tabl1 ADD FULLTEXT INDEX (column1);

SELECT ID FROM table1 WHERE MATCH(column1, column2) AGAINST ('text')

The following is wrong because the MATCH() references two columns but the index is defined for three columns.

ALTER TABLE tabl1 ADD FULLTEXT INDEX (column1, column2, column3);

SELECT ID FROM table1 WHERE MATCH(column1, column2) AGAINST ('text')

The following is wrong because the MATCH() references two columns but each index is defined for one column.

ALTER TABLE tabl1 ADD FULLTEXT INDEX (column1);
ALTER TABLE tabl1 ADD FULLTEXT INDEX (column2);

SELECT ID FROM table1 WHERE MATCH(column1, column2) AGAINST ('text')

The following is wrong because the MATCH() references two columns but in the wrong order:

ALTER TABLE tabl1 ADD FULLTEXT INDEX (column1, column2);

SELECT ID FROM table1 WHERE MATCH(column2, column1) AGAINST ('text')

In summary, use of MATCH() must reference exactly the same columns, in the same order, as one fulltext index definition.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...