MATCH (
col1
,col2
,...) AGAINST (expr
[search_modifier
])
search_modifier:
{
IN NATURAL LANGUAGE MODE
| IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION
| IN BOOLEAN MODE
| WITH QUERY EXPANSION
}
MySQL has support for full-text indexing and searching:MySQL支持全文索引和搜索:
A full-text index in MySQL is an index of type MySQL中的全文索引是FULLTEXT
.FULLTEXT
类型的索引。
Full-text indexes can be used only with 全文索引只能用于InnoDB
or MyISAM
tables, and can be created only for CHAR
, VARCHAR
, or TEXT
columns.InnoDB
或MyISAM
表,并且只能为CHAR
、VARCHAR
或text
列创建。
MySQL provides a built-in full-text ngram parser that supports Chinese, Japanese, and Korean (CJK), and an installable MeCab full-text parser plugin for Japanese. MySQL提供了一个内置的支持中文、日文和韩文(CJK)的全文ngram解析器,以及一个可安装的MeCab日语全文解析器插件。Parsing differences are outlined in Section 12.10.8, “ngram Full-Text Parser”, and Section 12.10.9, “MeCab Full-Text Parser Plugin”.第12.10.8节,“ngram全文解析器”和第12.10.9节,“MeCab全文解析器插件”概述了解析差异。
A 创建表时,可以在FULLTEXT
index definition can be given in the CREATE TABLE
statement when a table is created, or added later using ALTER TABLE
or CREATE INDEX
.CREATE TABLE
语句中给出全文索引定义,或者稍后使用ALTER TABLE
或CREATE 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 existing FULLTEXT
index.FULLTEXT
索引的表中,然后再创建索引要比将数据加载到具有现有FULLTEXT
索引的表中快得多。
Full-text searching is performed using 全文搜索是使用MATCH() AGAINST()
syntax. MATCH() AGAINST()
语法执行的。MATCH()
takes a comma-separated list that names the columns to be searched. MATCH()
采用逗号分隔的列表来命名要搜索的列。AGAINST
takes a string to search for, and an optional modifier that indicates what type of search to perform. AGAINST
接受一个要搜索的字符串和一个可选的修饰符,该修饰符指示要执行的搜索类型。The search string must be a string value that is constant during query evaluation. 搜索字符串必须是在查询求值期间保持不变的字符串值。This rules out, for example, a table column because that can differ for each row.例如,这排除了表列的可能性,因为每行的表列可能不同。
There are three types of 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, with the exception of double quote (") characters. 除了双引号("
)字符外,没有特殊运算符。The stopword list applies. 非索引词列表适用。For more information about stopword lists, see Section 12.10.4, “Full-Text Stopwords”.有关非索引词列表的更多信息,请参阅第12.10.4节,“全文非索引词”。
Full-text searches are natural language searches if the 如果给定了IN NATURAL LANGUAGE MODE
modifier is given or if no modifier is given. IN NATURAL LANGUAGE MODE
修饰符或未给定修饰符,则全文搜索是自然语言搜索。For more information, see Section 12.10.1, “Natural Language Full-Text Searches”.有关更多信息,请参阅第12.10.1节,“自然语言全文搜索”。
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. 它还可以包含一些操作符,这些操作符指定了一些要求,比如一个单词必须出现在匹配的行中,或者在匹配的行中不出现,或者它的权重应该比通常的高或低。Certain common words (stopwords) are omitted from the search index and do not match if present in the search string. 某些常用词(stopwords)将从搜索索引中省略,如果出现在搜索字符串中,则不匹配。The IN BOOLEAN MODE
modifier specifies a boolean search. IN BOOLEAN MODE
修饰符指定布尔搜索。For more information, see Section 12.10.2, “Boolean Full-Text Searches”.有关更多信息,请参阅第12.10.2节,“布尔全文搜索”。
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
or WITH QUERY EXPANSION
modifier specifies a query expansion search. IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION
或WITH QUERY EXPANSION
修饰符指定查询扩展搜索。For more information, see Section 12.10.3, “Full-Text Searches with Query Expansion”.有关更多信息,请参阅第12.10.3节,“带查询扩展的全文搜索”。
For information about 有关FULLTEXT
query performance, see Section 8.3.5, “Column Indexes”.FULLTEXT
查询性能的信息,请参阅第8.3.5节,“列索引”。
For more information about 有关InnoDB
FULLTEXT
indexes, see Section 15.6.2.4, “InnoDB Full-Text Indexes”.InnoDB
全文索引的更多信息,请参阅第15.6.2.4节,“InnoDB全文索引”。
Constraints on full-text searching are listed in Section 12.10.5, “Full-Text Restrictions”.全文搜索的局限性在第12.10.5节“全文限制”中列出。
The myisam_ftdump utility dumps the contents of a MyISAM
full-text index. myisam_ftdump
实用程序转储MyISAM
全文索引的内容。This may be helpful for debugging full-text queries. 这可能有助于调试全文查询。See Section 4.6.3, “myisam_ftdump — Display Full-Text Index information”.请参阅第4.6.3节,“myisam_ftdump——显示全文索引信息”。