MySQL fulltext index - mysql

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.

Related

Does MySQL make full table scan when result not found in other indexes

Lets say we have an ordinary table with the following structure: id column which is primary key, several other columns each of which has index key (single index key) and one column with unique key (instead of index key).
If we search by one of the columns with index key and no result is found in the index (lets assume that mysql will use the index for the search) will mysql do full table scan to verify that there is no result matching the criteria?
Almost the same scenario like the above but this time instead of searching by column with index key it will search by the column with unique key. Will mysql do full table scan?
Thanks in advance for the answers!
If we search by one of the columns with index key and no result is found in the index (lets assume that mysql will use the index for the search) will mysql do full table scan to verify that there is no result matching the criteria?
No. There would still be no result. What would be the point?
Almost the same scenario like the above but this time instead of searching by column with index key it will search by the column with unique key. Will mysql do full table scan?
Same question: same answer. The index being unique has no bearing.
The only way a full table scan could yield a different result from an index scan is if there is something wrong with the index.
If you have index wont be full scan.
If you dont found anything in one column why would you look for other columns?

FULLTEXT search NOT working on two columns

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.

MySQL fulltext search with different permutations

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).

have 3 FULLTEXT indexes on same table.. how to merge them?

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`
);

Problems using MySQL FULLTEXT search

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