MySQL full-text search-Boolean search

Source: Internet
Author: User
Tags mysql tutorial
Using INBOOLEANMODE to modify the program, MySQL can also perform a Boolean full-text search: mysqlSELECT * FROMarticlesWHEREMATCH (title, body)

Using in boolean mode to modify the program, MySQL can also perform a BOOLEAN full-text search: mysql SELECT * FROM articles where match (title, body) -AGAINST ('+ MySQL-yoursql' in boolean mode); + ---- + ----------------------- + ------------------------------------- + | id | tit

Using in boolean mode to modify the program, MySQL can also perform a BOOLEAN full-text search:

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

This query Retrieves all rows containing the word "MySQL", but does not retrieve rows containing the word "YourSQL.

Boolean full-text search has the following features:

◆ They do not use 50% domain values ..

◆ They do not classify rows in the order of weak correlations. You can see this from the above query results: the row with the highest relevance is a row containing two "MySQL", but it is listed at the last position rather than the start position.

◆ Even if FULLTEXT is not available, they can still work, although the search execution speed in this method is very slow.

◆ Full-text parameters of Minimum word length and maximum word length are applicable.

◆ Applicable to stopword.

The performance of Boolean full-text search supports the following operators:

◆ +

A leading plus sign indicates that the word must appear at the beginning of each returned line.

◆-

A leading minus sign indicates that the word cannot appear in any returned row.

◆ (No operator)

In the default state (when + or-is not specified), the word is dispensable, but the row level containing the word is higher. This is similar to the operation when MATCH ()... AGAINST () does not use in boolean mode to modify the program.

◆> <

These two operators are used to change the effect of a word on the values related to a row. > The operator enhances its influence, while <操作符则减弱其影响。请参见下面的例子。 < p>

◆ ()

Parentheses are used to divide words into subexpressions. The Section enclosed in parentheses can be nested.

◆ ~

A leading font size is used as a negative character to deny the influence of a word on the correlation of the row. This is useful for marking "noise (useless information)" words. Rows containing such words are of lower grade than other rows, but because they may be used together with the hyphen (-), the Police Station will not use any information at any time.

◆ *

An asterisk is used as a truncation character. Different from other symbols, it should be appended to the word to be truncated.

◆"

A phrase ('"') enclosed in double quotation marks matches only the row containing the input format of the phrase on the word. The full text engine Splits a phrase into a word and searches for the word in the FULLTEXT index. Non-word characters do not require strict match: phrase search only requires that the words contained in the search phrase are in the same order and the words are in the same order. For example, "test phrase" matches "test, phrase ".

If the word contained in the phrase does not exist in the index, the result is null. For example, if all words are disabled or the length is smaller than the minimum length of the indexed words, the result is null.

The following example shows some search strings that use Boolean full-text symbols:

◆ 'Apple bana'

Search for rows that contain at least two words.

◆ '+ Apple + juice'

Search for rows containing both words.

◆ '+ Apple macintosh'

Find the row that contains the word "apple". If the row also contains the word "macintosh", it is listed as a higher level.

◆ '+ Apple-macintosh'

Find a line that contains the word "apple" but does not contain the word "macintosh.

◆ '+ Apple + (> turnover

Find the rows that contain the words "apple" and "turnover", or those that contain "apple" and "strudel" (in no order ), however, rows that contain "apple turnover" are arranged at a higher level than those that contain "apple strudel.

◆ 'Apple *'

Search for rows that contain "apple", "apples", "applesauce", or "applet.

◆ '"Some words "'

Search for rows that contain the original phrase "some words" (for example, rows that contain "some words of wisdom", rather than rows that contain "some noise words ). Note that the '"' symbol of the surrounding phrase is an operator character that defines the phrase. They are not quotation marks surrounding the search string itself.

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.