Mysql full-text search for Chinese applications

Source: Internet
Author: User
Today, we will introduce the mysql full-text search application. The storage engine type of the full-text search table must be MyISAM. Otherwise, full-text search is not supported.

Today, we will introduce the mysql full-text search application. The storage engine type of the full-text search table must be MyISAM. Otherwise, full-text search is not supported.

First, use the following table as an example:

The Code is as follows:


01. create table articles (02.id int unsigned AUTO_INCREMENT not null primary key, 03. title VARCHAR (200), 04. body TEXT, 05. FULLTEXT (title, body) 06 .) ENGINE = MyISAM default charset = utf8;

MySQL uses Match () and Against () to perform full-text search, for example:

The Code is as follows:

SELECT body FROM articles WHERE Match (body) Against ('www .phpddt.com ');

The Match above is to search for the specified column, and Against ('www .phpddt.com ') is to search for the specified word

In addition:

Using the QUERY extension with query expansion, more results will be searched (mysql will search the Useful Words in the matched rows again, so that more results will be searched, but it may not be what you want );

Use BOOLEAN text to search in boolean mode, similar to the syntax we usually use when using a search engine: logic and, logic or, logical non-. Supported BOOLEAN operators are as follows:

Full-text boolean operator:
Bytes --------------------------------------------------------------------------------------------------------------
| Operator | description |
Bytes --------------------------------------------------------------------------------------------------------------
| + | Contain, the word must exist
|-| Exclude, the word must not appear
|> | Include and add a level value
| <| Include and reduce the level value
| () | Use phrases as subexpressions (allow these subexpressions to be included, excluded, and arranged as a group)
| ~ | Cancels the sorting value of a word
| * | Wildcard at the end of the word
| "" | Define a phrase (unlike the list of individual words, which matches the entire phrase to include or exclude this phrase)
Bytes ----------------------------------------------------------------------------------------------------------------

The usage is as follows:

The Code is as follows:

SELECT * FROM articles where match (title, body)

AGAINST ('+ apple-banana' in boolean mode );

+ Indicates AND, which must be included. -Indicates NOT, that is, NOT included.

The Code is as follows:

SELECT * FROM articles where match (title, body)

AGAINST ('apple banana 'in boolean mode );

There is a space between apple and banana, and a space indicates OR, that is, at least one of apple and banana is included.

The Code is as follows:

SELECT * FROM articles where match (title, body)

AGAINST ('+ apple banana' in boolean mode );

It must contain apple, but if it also contains banana, it will get a higher weight.

The Code is as follows:

SELECT * FROM articles where match (title, body)

AGAINST ('+ apple ~ Banana 'in boolean mode );

~ Is an exclusive OR operator that we are familiar. The returned record must contain apple, but if it also contains banana, the weight is reduced. However, it is not strict with apple-banana, because the latter does not return if it contains banana.

The Code is as follows:

SELECT * FROM articles where match (title, body)

AGAINST ('+ apple + (> banana

Returns records that contain both apple and banana, or both apple and orange. However, records that contain both apple and banana have a higher weight than those that contain both apple and orange.

Mysql full-text search in linux.

The Code is as follows:

Centos6
Xampp1.7.7
Mysql5.5

#/Opt/lampp/bin/mysql-uroot-ppassword

Mysql> show variables like 'in in _ dir ';
Plug-In Path:/opt/lampp/lib/mysql/plugin

# Wget http://mysqlcft.googlecode.com/files/mysqlcft-1.0.0-x86_64-bin.tar.gz
# Tar zxvf mysqlcft-1.0.0-x86_64-bin.tar.gz
# Cp mysqlcft. so/opt/lampp/lib/mysql/plugin

#/Opt/lampp/bin/mysql-uroot-ppassword
Mysql> install plugin mysqlcft SONAME 'mysqlcft. so ';
Mysql> SELECT * FROM mysql. plugin;
Mysql> show plugins;


Alter ignore table articles add fulltext index cnFullIndex (title, body) with parser mysqlcft;

SELECT * FROM articles where match (title, body) AGAINST ('beijing' IN BOOLEAN MODE

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.