How do I add a column to an existing FULLTEXT index? - php

I created a FULLTEXT index on a table in a MySql database, and left out a column when I did so. I have been trying to figure out how to add this column so that it can be searched against along with the other columns in this table that have already been indexed.
I have searched SO and the web, but am not getting anywhere. I tried going into phpMyAdmin, and when you click on the table and then look at the structure, all the way on the right there is a dropdown that says "More." This has a "Fulltext" option that seems to add fulltext indexing to the column, so I did this, but it is still not allowing me to search the column.
Did I add FULLTEXT to this column? Either way, how do I get this to work?

For SQL Server users, it can be done like this:
ALTER FULLTEXT INDEX ON [table_name] ADD ([column_name])

ALTER TABLE foo DROP FULLTEXT old_ft_index_name, ADD FULLTEXT(this, that);

Related

PHP/MySQL: match / against escaping stopword

Here's my query:
SELECT * from description WHERE (match(description) AGAINST ( '+will +smith' in boolean mode))
I'm aware that will is a stopword that's why i'm getting an empty result.
How would it work that i can still use both words for this query? Do i need to escape it in somekind of way?
There isn't a way to "escape" a stopword for a given search. Think of it this way: when creating the fulltext index, it skips indexing words if they are stopwords. That is, the words are not stored in the fulltext index. So you can't subsequently escape the word in a given search and have a word magically appear in the fulltext index since that wasn't included when the index was created.
Assuming you are using fulltext search with InnoDB, the solution is apparently to define your own table storing stopwords. Then you can put a customized set of words into the table, and use the configuration variable innodb_ft_server_stopword_table to make your instance of MySQL use your custom table before creating your fulltext index. This way, the word you want to be indexed will be included as it builds the fulltext index.
See https://dev.mysql.com/doc/refman/8.0/en/fulltext-stopwords.html
But this is a global variable, so it will affect all fulltext index creation on all tables on that MySQL instance. I suppose you could set the innodb_ft_server_stopword_table to your custom table, build your fulltext index, and then set the option back to its usual value. But that would be tricky, because anytime you rebuild your fulltext index (for instance during an alter table or optimize table), it would revert to the default stopwords.

How to make a column common from unique in phpmyadmin

I have created table in there I choosed a column to be unique AND now I want that column to be common not unique in phpmyadmin. I could not found any option like that. How can i do that ?
Can anyone tell me how to do this
I found this on the w3c tutorial website:
ALTER TABLE Persons
DROP INDEX UC_Person;
I tried on a table with unique contraint. It worked for the email column but not the username column. Here's the link.
https://www.w3schools.com/sql/sql_unique.asp
Good luck hope it is what you need.

PDOException' with message 'SQLSTATE[HY000]: General error:1191 [duplicate]

I'm working with fulltext, I executed an command to add the fulltext index to multiple comments, and returned no errors, then I did:
SELECT * FROM products WHERE MATCH(`brand`) AGAINST('Skoda');
Which is in the brand column - but I get following:
Can't find FULLTEXT index matching the column list
Eventho, when my table looks like this:
FULLTEXT KEY `name` (`name`,`breadcrumb`,`description`,`brand`,`price`,`year`,`km`,`usage`,`type`)
Is it because I should use the name instead? to do the search? Or what can be wrong.
Assuming you are using MyISAM engine, Execute:
ALTER TABLE products ADD FULLTEXT(brand);
The fulltext index should contain exactly the same number of columns, in same order as mentioned in MATCH clause.
If you don't feel like having the columns in the same order as in the match clause( or the same number), you can always use 'OR' that is:
ALTER TABLE products ADD FULLTEXT(brand);
ALTER TABLE products ADD FULLTEXT(product_name);
SELECT * FROM products WHERE MATCH(brand) AGAINST('+Skoda*' IN BOOLEAN MODE) OR MATCH(product_name) AGAINST('+productName*' IN BOOLEAN MODE)
When everything was right and still got this error I found that the KEYS were disabled. A simple error that is sometimes overlooked:
Make sure you have enabled the keys on that table.
It didn't work for me when I had disabled the keys. But when I enabled the keys ALTER TABLE table name ENABLE KEYS; it worked fine
I found I also needed to do this on my instance as the index was not visible. It was a checkbox while exploring MySQL Workbench. While invisible the index is not reachable by a query.
ALTER TABLE products ALTER INDEX brand VISIBLE;
Make sure the table engine is set to MyISAM.

mysql alter table order by not working

I have searched over net a lot. What I could understand is that this thing has been faced by many people before me and it has also been filed as mysql bugs. But I couldn't find any solution to this. The problem is just that I can't get this command working-
alter table areas order by area_name;
I get this warning-
ORDER BY ignored as there is a user-defined clustered index in the table 'areas'
I just want to sort the table on the basis of 'area_name', that is, names of areas. Just to add, I am trying to do this in the database of my laravel app.
If the db engine is InnoDB, then you can't do this.
From the doc:
ORDER BY does not make sense for InnoDB tables because InnoDB always
orders table rows according to the clustered index.

Can't find FULLTEXT index matching the column list (indexes is set)

I'm working with fulltext, I executed an command to add the fulltext index to multiple comments, and returned no errors, then I did:
SELECT * FROM products WHERE MATCH(`brand`) AGAINST('Skoda');
Which is in the brand column - but I get following:
Can't find FULLTEXT index matching the column list
Eventho, when my table looks like this:
FULLTEXT KEY `name` (`name`,`breadcrumb`,`description`,`brand`,`price`,`year`,`km`,`usage`,`type`)
Is it because I should use the name instead? to do the search? Or what can be wrong.
Assuming you are using MyISAM engine, Execute:
ALTER TABLE products ADD FULLTEXT(brand);
The fulltext index should contain exactly the same number of columns, in same order as mentioned in MATCH clause.
If you don't feel like having the columns in the same order as in the match clause( or the same number), you can always use 'OR' that is:
ALTER TABLE products ADD FULLTEXT(brand);
ALTER TABLE products ADD FULLTEXT(product_name);
SELECT * FROM products WHERE MATCH(brand) AGAINST('+Skoda*' IN BOOLEAN MODE) OR MATCH(product_name) AGAINST('+productName*' IN BOOLEAN MODE)
When everything was right and still got this error I found that the KEYS were disabled. A simple error that is sometimes overlooked:
Make sure you have enabled the keys on that table.
It didn't work for me when I had disabled the keys. But when I enabled the keys ALTER TABLE table name ENABLE KEYS; it worked fine
I found I also needed to do this on my instance as the index was not visible. It was a checkbox while exploring MySQL Workbench. While invisible the index is not reachable by a query.
ALTER TABLE products ALTER INDEX brand VISIBLE;
Make sure the table engine is set to MyISAM.

Categories