Home > Database > Mysql Tutorial > body text

Things you need to pay attention to when implementing full-text retrieval using MySQL's FULLTEXT

小云云
Release: 2017-12-13 14:38:11
Original
1760 people have browsed it

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);
Copy after login

Next, query the data:

 SELECT * FROM table_name WHERE MATCH (filed_1,filed_2) AGAINST ('keyword');
Copy after login

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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!