Mysql full text search for the use of match against

  • 2020-05-12 06:19:23
  • OfStack

For large databases, loading data into a table without an FULLTEXT index and then creating an index using ALTER TABLE (or CREATE INDEX) would be very fast. Loading data into a table that already has an FULLTEXT index would be very slow.
1. Prerequisites for fulltext retrieval using Mysql full text
The type of the table must be MyISAM
The field type for establishing full-text retrieval must be char,varchar,text

2. Set up the advance configuration of full-text search
Since the default configuration of Mysql is that the length of the indexed word is 4, to support Chinese characters, first change this.
*Unix user wants to modify my.cnf,1. This file is in /etc/ my.cnf, if not found, first look for 1. find / -name 'my.cnf'
Add in the [mysqld] location:
ft_min_word_len = 2
Other properties are
ft_wordlist_charset = gbk
ft_wordlist_file = /home/soft/mysql/share/mysql/wordlist-gbk.txt
ft_stopword_file = /home/soft/mysql/share/mysql/stopwords-gbk.txt
A little explanation 1:
ft_wordlist_charset represents the character set of the dictionary, currently supported well (UTF-8, gbk, gb2312, big5)
ft_wordlist_file is a word list file. Each line contains one word and its frequency (separated by tabs or Spaces)
ft_stopword_file means filter out non-indexed word table, 1 row 1.
The minimum length of ft_min_word_len indexed word is 4 by default, changed to 2 to support Chinese word

3. Establish full-text search
The fields are identified with the FullText keyword in the build table, and the existing tables are indexed with ALTER TABLE (or CREATE INDEX)
CREATE fulltext INDEX index_name ON table_name(colum_name);

4. Use full-text search
The MATCH function is used in the WHERE sentence of SELECT, and the key words of the index are identified by AGAINST. IN BOOLEAN MODE only contains the key words, and does not care about the starting position.
SELECT * FROM articles WHERE MATCH (tags) AGAINST (' tourism 'IN BOOLEAN MODE);

5. Please refer to Mysql official website for detailed instructions
http://dev.mysql.com/doc/refman/5.1/zh/functions.html#fulltext-search
This is Mysql 5.1, but 4.X can also be used as a reference, basic 1. I used Mysql 4.1.

MySQL supports full-text indexes (Full-Text) for a long time. Currently, fulltext is a single index type that only applies to MyISAM tables. Moreover, there are restrictions on the data types that can be used to define index columns. fulltext can create table 1 is defined, at the same time or after the table has been created by statements alter table or create index to additional indexes, anyhow has had the effect of 1 sample, but the efficiency is a significant difference of the two, a large number of experiments show that for large number of tables, the speed of loading the data first, then to define the full-text index is far better than the one already defined inside a full-text index table insert the speed of the large amounts of data. 1 will surely ask: what is this asking? In fact, the reason is very simple, the former need only once to your index list operation, sorting comparison is done in memory, and then written to the hard disk; The latter is to go to the hard disk to read the index table one by one and then compare and finally write, naturally so the speed will be slow. MySQL implements its full-text index query through the functions match() and against(). The field names in match() should correspond to field 1 defined in fulltext. If boolean mode is used, it is also allowed to include only one field in fulltext, not all of them. against() defines the string to search for and the mode in which the database is required to perform a full-text index search query. Here is an example to introduce the three search patterns supported by fulltext below.

MySQL full text index and Chinese word segmentation summary and 1 - like keyword search process
http://www.tzlink.com/info/show.php?aid=4532

mysql full text search for Chinese word segmentation
http://hi.baidu.com/agg230/blog/item/33d3d50eada260e337d1225b.html

Support Chinese MySQL 5.1+ full text search word segmentation plugin
http://hi.baidu.com/start_and_end/blog/item/6d6ab918b7d3800334fa412e.html

Use 1 search engines will find that the participle only occurs when the entire hit is 0.
For details on word segmentation, please refer to the baidu search results below:

· if you search for "xu zu ning ning", the result will be "xu zu" + "ning ning". (in the case of searching people's names, it may have a dictionary of 100 family names, and automatically puts the first word after the family name before the first word.)
· search for "xu ning wish", and the result is "xu ning wish". (prefer to be owned by xu. Same as above. Because xu is a surname.)
· search for "xuzu would rather", and the result is "xuzu" + "would rather". (because "would rather" is a word, so "xu" only with "zu".)
· search for "xu zuning gao" and the result is "xu zuning". (because "ning gao" is not a key word, "ning" belongs to the former word. The word "high" may be omitted because it is a single word to improve search efficiency.


Related articles: