Saturday, May 22, 2010

MySQL MATCH AGAINST Query ERROR 1191

I came across this problem when I ran into a client who needed Boolean search functionality on his site. The previous query he had was using LIKEs to do the searching on 6 columns. I told him about using a new query that used FULLTEXT indexes and continued about the performance benefits and also overhead this might cause as their data changes overtime. Naturally, I gave him a cronjobs script that basically optimizes the table to help him with maintenance. The problem arose when I implemented the query (Match..Against) I kept on getting:
ERROR 1911 (HY000): Can't find FULLTEXT index matching the column list.
I didn't understand why; I placed the indexes on a temporary table and queried the table with the appropriate columns defined in the MATCH() function. Then, I read in the MySQL forum that you were suppose to have FULLTEXT indexes on the columns separately and in addition one index that has all of the columns used in your query. I used an ALTER TABLE command to add an index to all the columns separately and collectively.

Queries used:
ALTER TABLE table1 ADD FULLTEXT (col1);
ALTER TABLE table1 ADD FULLTEXT (col2);
ALTER TABLE table1 ADD FULLTEXT (col3);
...ALTER TABLE table1 ADD FULLTEXT (col6);

ALTER TABLE table1 ADD FULLTEXT search_ft1 (col1,col2, col3,...col6);
ALTER TABLE command creates a temp table in memory and any changes you make to the table is done on the copy. When the changes are made the original table is discarded and the temp is renamed to the original table name.

Guess what, it gave me THE SAME ERROR 1911!!!

Next, I tried using a REPAIR TABLE...QUICK to rebuild the indexes. After that didn't work, I finally thought of dropping the indexes I created add creating the indexes using the syntax:
CREATE FULLTEXT INDEX search_ft ON table1 (col1,col2 col3,...col6) ;
FINALLY WORKED!!! Now my client enjoys Boolean searches on his FULLTEXT columns.

1 comment:

  1. When using the query: CREATE FULLTEXT INDEX search_ft ON table1 (col1,col2 col3,...col6); it gave me this error message: ERROR 1283 (HY000): Column 'ar_title' cannot be part of FULLTEXT index

    ReplyDelete

Please leave me a few lines and tell me what you think.