MySQL-Full Text Search

Full-Text Search

The premise of using full-text search is that the index covers the searched columns and updates the index as the data changes.

MySQL automatically maintains a full-text index (when data is added, updated, or deleted, the index page will be updated accordingly).

The full-text search will output the result set in order of priority.

Precautions:

  1. Do not use FULLTEXT when importing data. Import the data first, then modify the table and define FULLTEXT.
  2. It is not case sensitive, if you want to distinguish, use BINARY mode.
  3. Sort the result set. The result set obtained by the LIKE search will not be sorted, and the text result set returned by the full-text search will be sorted according to the goodness of the text matching (higher-level lines are returned first).

Match() specifies the column to be searched. The value passed to Match() must be the same as defined by FULLTEXT(), and the sequence must be correct when multiple columns are used.

Against() specifies the search expression to be used.

Full-Text Search Functions

1.	MATCH (col1,col2,...) AGAINST (expr [search_modifier])  
2.	  
3.	search_modifier:  
4.	{  
5.	       IN NATURAL LANGUAGE MODE  
6.	     | IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION  
7.	     | IN BOOLEAN MODE  
8.	     | WITH QUERY EXPANSION  
9.	}

MySQL supports full-text index and full-text search

  • The full-text index in MySQL is a full-text index.
  • In MySQL, full-text indexes are only for InnoDB and MyISAM engines, and columns of type CHAR/VARCHAR/TEXT.
  • MySQL provides content text analysis.
  • You can define a full-text index when creating a table. After the table is created, you can create a full-text index by modifying the table.
  • For large data sets, using a full-text index will increase the speed of table loading data.

Full text search syntax

1.	MATCH(c1,c2,  ....) ... AGAINST(str)  

Multiple columns in MATCH are separated by commas, and the search string must be a constant .

Three types of full text search

1. Natural language search interprets the search string as a phrase in natural human language (phrase in free text). Except for the double quote (") character, there are no special operators.

2. Boolean search uses special query language rules to interpret the search string. The query string contains not only the keywords of the query, but also operators such as =,> and <.

3. Query expansion search is a modification of natural language search. The search string is used to perform natural language searches. Then, add the word of the most relevant line returned by the search to the search string, and then perform the search again. The query returns the rows of the second search. The IN NATURAL LANGUAGE mode with query expansion or query expansion modifier specifies the query expansion search.

Boolean Full-Text Searches

When using the IN BOOLEAN MODE modifier, MySQL performs a Boolean full-text search. With this modifier, certain characters have special meaning at the beginning or end of words in the search string.

The +/- modifier means that the character must be displayed/not displayed. The following query indicates that MySQL is included, but YourSQL is not included.

1.	mysql> SELECT * FROM articles WHERE MATCH (title,body)  
2.	    AGAINST ('+MySQL -YourSQL' IN BOOLEAN MODE);  
3.	+----+-----------------------+-------------------------------------+  
4.	| id | title                 | body                                |  
5.	+----+-----------------------+-------------------------------------+  
6.	|  1 | MySQL Tutorial        | DBMS stands for DataBase ...        |  
7.	|  2 | How To Use MySQL Well | After you went through a ...        |  
8.	|  3 | Optimizing MySQL      | In this tutorial, we show ...       |  
9.	|  4 | 1001 MySQL Tricks     | 1. Never run mysqld as root. 2. ... |  
10.	|  6 | MySQL Security        | When configured properly, MySQL ... |  
+----+-----------------------+-------------------------------------+

Boolean logic: + stands for AND,-stands for NOT, and no modifier stands for OR.

Guess you like

Origin blog.csdn.net/A_bad_horse/article/details/112789376