I am creating a mysql fulltext search engine for my website, and I have an advanced search page that allows the user to limit which columns they would like to search under. However, whenever I make a fulltext search index, all the columns used in that index must be used or else I get an error message. Is there any way to make a mysql index for fulltext where I can use just some of the columns?
For example I have 5 columns in my index, made by this statement:
ALTER TABLE table1 ADD FULLTEXT fulltext_index(subject, course, prof, semester,
year);
If I wanted to search under only subject and course, I would get the error:
#1191 - Can't find FULLTEXT index matching the column list
You just need to create more indexes for each possible combination you want to search:
alter table table1 add fulltext fulltext_index2(subject,course);
alter table table1 add fulltext fulltext_index3(course,semester,year);
Etc...see if that solves the issue.
No, a fulltext index requires you to use all of the columns. If you want to use only some of them, you'll need a separate fulltext index for every permutation. I haven't tested it, but you MAY get around it by using only columns in the order specified. e.g. an index on columns (a,b,c) might allow you to search only (a,b) because they're listed first, but not (a,c) or (b,c).
Related
Background:
Hey I'm using MySQL 5.6.17 InnoDB, I've read on mysql website that FULLTEXT is now avaiable for InnoDB in 5.6+ version. so i don't have to change from InnoDB to MyISAM Here is the link I altered TWO of my table columns for FULLTEXT search by using the following query
ALTER TABLE `es_officers` ADD FULLTEXT Index_officer_name (es_officer_name)
ALTER TABLE `es_officers` ADD FULLTEXT Index_officer_fname (es_officer_fname)
Altered Table Registered in Information Schema:
Then i checked in my information schema if the altered table columns are registered or not by running the following query
SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME
FROM statistics
WHERE index_type LIKE 'FULLTEXT%'
It showed me exacttly two results which i was expecting
Problem:
when i write a query to MATCH a sting AGAINST two columns it gives me an error
SELECT * FROM `es_officers` WHERE MATCH (es_officer_name, es_officer_fname) AGAINST ('abc')
#1191 - Can't find FULLTEXT index matching the column list
BUT:
when i try to query the columns separately like below it works absolutely fine
SELECT * FROM `es_officers` WHERE MATCH (es_officer_name) AGAINST ('abc')
SELECT * FROM `es_officers` WHERE MATCH (es_officer_fname) AGAINST ('abc')
I don't know what is it I'm doing wrong, help is highly appreciated.
Multiples issues:
You have two separate fulltext indexes, each covering a single field. You have WHERE MATCH (es_officer_name, es_officer_fname) as your query, which requires a SINGLE index covering both fields. MySQL will not use two separate indexes for this query - it can't. that's not how fulltext indexing works. You need an alter ... fulltext (es_officer_name, es_officer_fname) instead added.
And even then, abc will fall under the default minimum word length and won't get indexed.
Besides, you can try something like:
SELECT * FROM es_officers
WHERE MATCH es_officer_name AGAINST ('abc') + MATCH es_officer_fname AGAINST ('abc')
Though, as Marc B said, 'abc' value is too short.
I'm trying to set up a FULLTEXT index in an existing db table (with like 50k records), with the command below, which worked:
ALTER TABLE `record_attributes` ADD FULLTEXT `FULLTEXT` (`content_text` ,`content_varchar`)
Problem is, when I try to do a MATCH AGAINST on that table, it gives me this error:
#1191 - Can't find FULLTEXT index matching the column list
I've been searching on google and didn't find anything that I could be doing wrong. Does the index have to be added on tables without any records?
Cheers
If you search by 1 column, fulltext index by 2 columns is not matching.
I'm creating tables using phpMyAdmin and want to define two different columns as indices. I'm not trying to create a multi-column index but phpMyAdmin creates them as such. Are there any possible issues with that? The fields don't relate to each other directly and both fields will not be used in WHERE clauses simultaneously.
Consider:
ALTER TABLE `documents` ADD INDEX (`offer_number`, `contract_number`);
And:
ALTER TABLE `documents` ADD INDEX (`offer_number`);
ALTER TABLE `documents` ADD INDEX (`contract_number`);
What's the difference?
MySQL can only make use of an index if the first column(s) of the index match the columns used in the query. In other words, if you perform a query where an index on contract_number could be used, the composite index won't be used since contract_number is not the first column in that key. The composite index could be used for a query where offer_number is used, however.
http://dev.mysql.com/doc/refman/5.0/en/multiple-column-indexes.html
http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html
Given what you say about these fields, they should not be a part of one multi column index.
If you want to create single column indexes on PhpMyAdmin, you need to create them one at a time.
on my table I have 3 different FULLTEXT indexes like so:
FULLTEXT KEY `product_name` (`product_name`,`product_description`),
FULLTEXT KEY `product_brand` (`product_brand`,`metal_type`,`primary_stone`,`product_type`,`product_type_sub`,`product_series`),
FULLTEXT KEY `primary_stone_sub` (`primary_stone_sub`)
This is because I added them after the fact like so:
ALTER TABLE cart_product ADD FULLTEXT(columnA, columnB);
Q1 How can I merge these 3 into 1 FULLTEXT index?
Q2 Also, so this doesn't happen again, how would I add a FULLTEXT column to the already existing FULLTEXT index?
Thanks!!!
It seems like you only want to have 1 FULLTEXT index, containing all of those columns. Is that right? You can also have several FULLTEXT indexes on this table, one containing all of the columns and others containing a subset. It all depends on your usage.
Just remember this caveat from the manual and make sure your fulltext index column list(s) match the columns you are querying against exactly:
The MATCH() column list must match exactly the column list in some FULLTEXT index definition for the table, unless this MATCH() is IN BOOLEAN MODE. Boolean-mode searches can be done on nonindexed columns, although they are likely to be slow.
The answer to both questions is that you need to drop the existing index and recreate it with an updated list of columns:
ALTER TABLE cart_product
DROP INDEX `product_name`,
DROP INDEX `product_brand`,
DROP INDEX `primary_stone_sub`,
ADD FULLTEXT INDEX `cart_product_fti` (
`product_name`,
`product_description`,
`product_brand`,
`metal_type`,
`primary_stone`,
`product_type`,
`product_type_sub`,
`product_series`,
`primary_stone_sub`
);
I have already posted a question about this, but the situation has changed sufficiently to warrant a new one.
I have a MySQL table called aromaProducts in which there are 7 columns with the FULLTEXT index, and which has three records in it. When I make a query against it like:
SELECT * FROM aromaProducts WHERE MATCH (title) AGAINST ('chamomile');
I get the correct result. However, when I try adding a second field to search in, I get an error:
Can't find FULLTEXT index matching the column list
Every column on its own works fine. I have also explicitly adding WITH QUERY EXPANSION and the same thing.
I have another table, aromaProducts1, and instead of assigning FULLTEXT to the fields one at a time, I assigned it to all 7 at the moment of table creation. Against this table, no queries work. When examining the table structure, the difference is this:
The first table shows each field having its own FULLTEXT index, while the second has one index, named title (the first field to have it assigned), and it applies to all seven fields.
All columns that I have made FULLTEXT are either VARCHAR or TEXT datatypes. I have no clue what the problem is.
You have to create the fulltext index on all columns you are going to match
If you want to match on (col1,col2,col3) you have to create fulltext index on col1,col2 and col3. If you want to match on(col1,col2) you have to implement another fulltext index(on col1 and col2), you can't use that one on col1, col2 and col3
you have to create one fulltext index with several columns, not one for each