Mysql Full-Text search match against usage _mysql

Source: Internet
Author: User
Tags create index
For large databases, it is very quick to load the data into a table with no Fulltext index and then use ALTER table (or CREATE index) to create the index. It will be very slow to load data into a table that already has a fulltext index.
1. Prerequisites for using MySQL Full-text search fulltext
The type of the table must be MyISAM
The field type that establishes Full-text search must be Char,varchar,text

2. Establish the advance configuration of Full-text search
Because MySQL's default configuration is to index the length of the word is 4, so to support the Chinese word, first change this.
*unix users to modify MY.CNF, general this file in/etc/my.cnf, if not found, first look find/-name ' my.cnf '
Add in [mysqld] location:
Ft_min_word_len = 2
Other attributes also have
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:
Ft_wordlist_charset represents the dictionary's character set, currently supported well (UTF-8, GBK, gb2312, Big5)
Ft_wordlist_file is a thesaurus file, each line including a word and its frequency (with a number of tabs or spaces separated, disambiguation dedicated)
Ft_stopword_file means to filter out the not indexed thesaurus, one line.
Ft_min_word_len the minimum length of the word added to the index, the default is 4, in order to support the Chinese word is changed to 2

3. Establishment of Full-text Search
Using the FULLTEXT keyword in a table, an existing table creates an index with ALTER table (or CREATE INDEX)
CREATE Fulltext INDEX index_name on table_name (COLUM_NAME);

4. Using Full-text Search
In the WHERE clause of SELECT, with the match function, the indexed keyword is identified with against, in BOOLEAN mode is only the keyword, not the location, the starting position.
SELECT * from articles WHERE MATCH (tags) against (' travel ' in BOOLEAN MODE);

5. Detailed description Please parameter MySQL official website
Http://dev.mysql.com/doc/refman/5.1/zh/functions.html
This is MySQL 5.1, but 4. X can also be used as a reference, basic one. I use MySQL 4.1.

MySQL supports Full-text indexing (full-text) for a long time now, Fulltext is an index type that applies only to MyISAM tables, and there are limits to the types of data that define indexed columns, only the following three combinations of Char, varchar, text. Fulltext can be defined together while creating a table, or after the table is created, by the statement ALTER TABLE or CREATE INDEX to append the index, in short, the effect is the same, but the efficiency of the two is very different, a large number of experiments prove that For a large number of tables, loading the data before defining the Full-text index is much faster than inserting large amounts of data into a table that has already been defined for full-text indexing. Must ask: What is this question? In fact, the reason is very simple, the former only need to do a one-time operation on your index list, sorting comparison is done in memory, and then write to the hard disk, the latter will be a hard drive to read the index table and then compare the final write, naturally this speed will be very slow. MySQL is the function of the match () and against () to implement its Full-text indexing query. The field names in match () are consistent with the fields defined in Fulltext, and if you are searching in Boolean mode, you can also allow only one field in Fulltext to be included, not all listed. Against () is defined as the string to search for and search queries that require the database to perform full-text indexing in which mode. The following is an example of the 3 search pattern supported by Fulltext.

mysql full-text indexing and Chinese word segmentation summary and the General keyword search process
http://www.tzlink.com/info/show.php?aid=4532

MySQL Full-text search Chinese participle
Http://hi.baidu.com/agg230/blog/item/33d3d50eada260e337d1225b.html

Chinese-supported MySQL 5.1+ full-text search word breaker
Http://hi.baidu.com/start_and_end/blog/item/6d6ab918b7d3800334fa412e.html

Home Search engine will find that participle of the situation is only now when the whole word hit 0 of the case.
and specific how participle, we can refer to the results of Baidu Search test:

• If the search "Xu Zuningning", the result is "Xu Zu" + "ningning". (in the case of a person's name, it may have a surnames dictionary that automatically follows the first word of the surname)
* search "Xu would rather", the result is "Xu would rather". (note "preferred" to "Xu" all.) Ditto. Because Xu is the surname. )
* search "Xu Zu would rather", the result is "Xu Zu" + "would rather". (because "prefer" is the word, so "Xu" only with "Zu". )
* search "Xu Zuning High", the result is "Xu Zuning". (because "Ning Gao" is not the key word, so "ning" belongs to the former word all. "Gao" may be omitted because it is a word, which improves the search efficiency of the former word. )

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.