对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
See how MongoDB 9.0 delivers up to 2x higher throughput.
MongoDB Branding Shape
Register now >
Docs 菜单

多分析器

您可以在索引定义中使用 multi 对象指定还用于对字段进行索引的备用分析器。除了默认分析器以外,在使用备用分析器对字段进行索引时,您可以使用默认分析器或备用分析器搜索集合。本页说明了如何使用 multi 在索引定义中指定备用分析器。

multi 路径选项仅适用于字符串类型的字段。

MongoDB Search 不支持嵌套多个 multi 对象层。

The following examples demonstrate index definitions on the fields in the sample_mflix.movies collection. If you load the collection on your cluster, you can create the example indexes using the Visual Editor or the JSON Editor in the Atlas UI or using mongosh.

以下示例索引定义使用 standard 分析器指定了 title 字段的索引。此索引定义还指定 lucene.french 分析器作为 title 字段的备用分析器,且名称为 frenchAnalyzer。

以下查询使用名为 frenchAnalyzer 的备用分析器来搜索字符串 liberte。

结果中的文档是匹配项,因为 frenchAnalyzer 将索引字符串 è Nous la Libertè 和查询术语liberte 缩减为基本词 libert。 使用 standard分析器进行搜索时, MongoDB搜索不会返回此文档,因为它不会删除变音符号。每个分析器为索引和查询生成以下词元(可搜索词):

分析器
Index Tokens
查询标记

标准分析器

è, nous , la , libertè

libertè

French 分析器

è, libert

libert

以下示例索引定义使用 standard 分析器指定 title 与 plot 字段的索引。此索引定义还指定 lucene.french 作为 title 与 plot 字段的备用分析器。

以下查询使用名为 frenchAnalyzer 的备用分析器在 title 与 plot 字段中搜索字符串 revolution 的匹配项。

结果中的文档在 title 和 plot 字段中包含查询术语。每个分析器为结果中每个文档的 title 字段创建以下标记(可搜索术语):

年份

分析器

Index Tokens

查询标记

2012

标准分析器
法语分析器

revolution
revolution

revolution
revolution

1985

标准分析器
法语分析器

revolution
revolution

revolution
revolution

2014

标准分析器
法语分析器

angels、of、revolution
angels、of、revolution

revolution
revolution

1970

标准分析器
法语分析器

start、the、revolution、without、me
start、the、revolution、without

revolution
revolution

1989

标准分析器
法语分析器

la、rèvolution、franèaise
revolution、franeais

revolution
revolution

对于这些结果中的第五个文档,frenchAnalyzer 删除了 title 字段中的标注字符,以便将此文档与查询词相匹配。