11.8. Full-Text Search Functions
[+/-]
MATCH (
col1
,col2
,...) AGAINST (expr
[search_modifier
])
search_modifier:
{
IN BOOLEAN MODE
| IN NATURAL LANGUAGE MODE
| IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION
| WITH QUERY EXPANSION
}
MySQL has support for full-text indexing and searching:
A full-text index in MySQL is an index of type
FULLTEXT
.Full-text indexes can be used only with
MyISAM
tables, and can be created only forCHAR
,VARCHAR
, orTEXT
columns.A
FULLTEXT
index definition can be given in theCREATE TABLE
statement when a table is created, or added later usingALTER TABLE
orCREATE INDEX
.For large data sets, it is much faster to load your data into a table that has no
FULLTEXT
index and then create the index after that, than to load data into a table that has an existingFULLTEXT
index.
Full-text searching is performed using MATCH() ... AGAINST
syntax. MATCH()
takes a comma-separated list that names the columns to be searched. AGAINST
takes a string to search for, and an optional modifier that indicates what type of search to perform. The search string must be a literal string, not a variable or a column name. There are three types of full-text searches:
A boolean search interprets the search string using the rules of a special query language. The string contains the words to search for. It can also contain operators that specify requirements such that a word must be present or absent in matching rows, or that it should be weighted higher or lower than usual. Common words such as “some” or “then” are stopwords and do not match if present in the search string. The
IN BOOLEAN MODE
modifier specifies a boolean search. For more information, see Section 11.8.2, “Boolean Full-Text Searches”.A natural language search interprets the search string as a phrase in natural human language (a phrase in free text). There are no special operators. The stopword list applies. In addition, words that are present in 50% or more of the rows are considered common and do not match. Full-text searches are natural language searches if the
IN NATURAL LANGUAGE MODE
modifier is given or if no modifier is given.A query expansion search is a modification of a natural language search. The search string is used to perform a natural language search. Then words from the most relevant rows returned by the search are added to the search string and the search is done again. The query returns the rows from the second search. The
IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION
orWITH QUERY EXPANSION
modifier specifies a query expansion search. For more information, see Section 11.8.3, “Full-Text Searches with Query Expansion”.
The IN NATURAL LANGUAGE MODE
and IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION
modifiers were added in MySQL 5.1.7.
Constraints on full-text searching are listed in Section 11.8.5, “Full-Text Restrictions”.
No comments:
Post a Comment