On this page本页内容
This tutorial describes how to specify the default language associated with the text index and also how to create text indexes for collections that contain documents in different languages.本教程介绍如何指定与文本索引关联的默认语言,以及如何为包含不同语言文档的集合创建文本索引。
text
Index¶The default language associated with the indexed data determines the rules to parse word roots (i.e. stemming) and ignore stop words. 与索引数据关联的默认语言决定了解析词根(即词干)和忽略停止词的规则。The default language for the indexed data is 索引数据的默认语言为english
.english
。
To specify a different language, use the default_language
option when creating the text
index. See Text Search Languages for the languages available for default_language
.
The following example creates for the quotes
collection a text
index on the content
field and sets the default_language
to spanish
:
text
Index for a Collection in Multiple Languagestext
索引¶If a collection contains documents or embedded documents that are in different languages, include a field named 如果集合包含不同语言的文档或嵌入文档,请在文档或嵌入文档中包含名为language
in the documents or embedded documents and specify as its value the language for that document or embedded document.language
的字段,并将该文档或嵌入文档的语言指定为其值。
MongoDB will use the specified language for that document or embedded document when building the 在构建text
index:text
索引时,MongoDB将使用该文档或嵌入文档的指定语言:
text
index.text
索引的默认语言。See Text Search Languages for a list of supported languages.有关支持的语言列表,请参阅文本搜索语言。
For example, a collection 例如,集合quotes
contains multi-language documents that include the language
field in the document and/or the embedded document as needed:quotes
包含多语言文档,这些文档根据需要包括文档和/或嵌入文档中的language
字段:
If you create a 如果在text
index on the quote
field with the default language of English.quote
字段上创建默认语言为英语的text
索引。
Then, for the documents and embedded documents that contain the 然后,对于包含该language
field, the text
index uses that language to parse word stems and other linguistic characteristics.language
字段的文档和嵌入文档,text
索引使用该语言解析词干和其他语言特征。
For embedded documents that do not contain the 对于不包含language
field,language
字段的嵌入式文档,
language
field, then the index uses the document’s language for the embedded document.language
字段,则索引将使用文档的语言作为嵌入文档的语言。For documents that do not contain the language
field, the index uses the default language, which is English.
To use a field with a name other than language
, include the language_override
option when creating the index.
For example, give the following command to use idioma
as the field name instead of language
:
The documents of the quotes
collection may specify a language with the idioma
field: