36

I am running the following query on tbl_query

select * from tbl_query q where match(q.query_desc,q.query_desc_details) against ('test1' WITH QUERY EXPANSION);

It's giving an error

16:46:22    select * from tbl_query q where match(q.query_desc,q.query_desc_details) against ('test1' WITH QUERY EXPANSION) LIMIT 0, 1000   Error Code: 1191. Can't find FULLTEXT index matching the column list    0.078 sec  

My table is like this

 CREATE TABLE `tbl_query` (
  `query_id` int(11) NOT NULL AUTO_INCREMENT,
  `query_desc` text NOT NULL,
  `query_desc_details` text,
  PRIMARY KEY (`query_id`),
  KEY `QUERY_DESC` (`query_desc`(333)) USING BTREE,
  KEY `QUERY_DESC_DETAILS` (`query_desc_details`(333)) USING BTREE
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

In database full text words boundaries are like

ft_max_word_len=    84
ft_min_word_len=    4  

I am searching against two column.
So my question is how to create the full text index for the table?

Mad Dog Tannen
  • 7,129
  • 5
  • 31
  • 55
Pradeep Kr Kaushal
  • 1,506
  • 1
  • 16
  • 29

4 Answers4

62

Fulltext with 2 columns you create like this

ALTER TABLE tbl_query
ADD FULLTEXT INDEX `FullText` 
(`query_desc` ASC, `query_desc_details` ASC);
Mad Dog Tannen
  • 7,129
  • 5
  • 31
  • 55
25
ALTER TABLE `TableName`
    ADD FULLTEXT INDEX `IndexName` (`ColumnName`);
16

This creates the index. This should work.

ALTER TABLE `TableName` ADD FULLTEXT index_name(column1, column2);
A Paul
  • 8,113
  • 3
  • 31
  • 61
  • I added the index but it's showing the same error. Something else need to be done? – Pradeep Kr Kaushal Feb 04 '14 at 11:52
  • 2
    nope it should work. Check once useing desc if it is there. Try restarting the mysql once. But this should work. – A Paul Feb 04 '14 at 11:55
  • `ALTER TABLE tbl_query ADD FULLTEXT index_name(query_desc,query_desc_details);` for 2 columns. – Mad Dog Tannen Feb 04 '14 at 11:59
  • @KayNelson Does not seem to work when the table has some content already and but when you create a fresh table it works. But is there as way to make it work on tables that is already has quite a bit of data ? I am using 10.1.21-MariaDB – VMN Nov 29 '17 at 12:24
2

Add the Index

ALTER TABLE table_name ADD FULLTEXT index_name(column1, column2);

To get the search result

SELECT * FROM table_name WHERE MATCH(column1, column2)
AGAINST('search string' IN NATURAL LANGUAGE MODE);

To drop the index

ALTER TABLE table_name
DROP INDEX index_name;