38

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?

5 Answers 5

64

Fulltext with 2 columns you create like this

ALTER TABLE tbl_query
ADD FULLTEXT INDEX `FullText` 
(`query_desc` ASC, `query_desc_details` ASC);
Sign up to request clarification or add additional context in comments.

3 Comments

What does ASC do?
@SupunKavinda 'ASC' indexes in ascending order whereas 'DESC' does it in descending
How do you use the 'FullText' index. I tried and it keeps saying Error 1054 Unknown column 'FullText'
27
ALTER TABLE `TableName`
    ADD FULLTEXT INDEX `IndexName` (`ColumnName`);

Comments

16

This creates the index. This should work.

ALTER TABLE `TableName` ADD FULLTEXT index_name(column1, column2);

4 Comments

Image
I added the index but it's showing the same error. Something else need to be done?
nope it should work. Check once useing desc if it is there. Try restarting the mysql once. But this should work.
ALTER TABLE tbl_query ADD FULLTEXT index_name(query_desc,query_desc_details); for 2 columns.
@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
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;

Comments

0

These are all ALTER but you can also use the CREATE INDEX syntax to add it:

CREATE FULLTEXT INDEX search_idx ON myDatabase.books (bookTitle, bookAuthor, bookText);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.