For English, MySQL's FULLTEXT attribute is very convenient and efficient to implement full-text retrieval, but there are some things you need to pay attention to during use. Do you know how much MySQL's FULLTEXT attribute implements full-text retrieval? In fact, the editor tested this thing It does not support Chinese, but since you are using it, there are still some things you should pay attention to.
First add the FULLTEXT attribute to the fields we need to retrieve (assuming that the table has been created):
alter table table_name add fulltext index(filed_1,filed_2);
Next, query the data:
SELECT * FROM table_name WHERE MATCH (filed_1,filed_2) AGAINST ('keyword');
This involves a lot of Important note:
MySQL stipulates that in full-text search, when the number of rows where the searched word is located is greater than or equal to half of the number of all searched rows, the searched word will be treated as a Common word, that is, it will not be displayed. (The specific conditions need to be determined by consulting the information)
Therefore, assuming that during the test, there is only one row of data in the table, so no matter how the above query statement is executed, the returned result is always empty. Don’t panic, add a few more data without keywords to be searched and you will get results~
Of course, MySQL provides a more powerful filtering of query results:
SELECT * FROM table_name WHERE MATCH (filed_1,filed_2) AGAINST (' keyword_1 -keyword_2' IN BOOLEAN MODE);
In this way, it will return the results containing keyword_1 data, and data containing keyword_2 will be filtered out.
Related recommendations:
mysql full-text search Chinese solutions and example code sharing
##PHP+MYSQL realizes full-text search and full-text search tools
SQL Server Full Text Search Introduction_PHP Tutorial
The above is the detailed content of Things you need to pay attention to when implementing full-text retrieval using MySQL's FULLTEXT. For more information, please follow other related articles on the PHP Chinese website!