对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

自定义分析器

MongoDB 搜索分析器通过执行一系列操作来转换、过滤器和群组字符序列,从而准备要索引的文档。您可以从Atlas用户界面定义自定义分析器来满足您的特定索引需求。

A custom MongoDB Search analyzer is made up of a tokenizer, an optional list of character filters, and an optional list of token filters. When MongoDB Search analyzes text with a custom analyzer, the text passes through the character filters first, then the tokenizer, and then the token filters.

自定义分析器采用以下语法:

语法
"analyzers": [
{
"name": "<name>",
"charFilters": [ <list-of-character-filters> ],
"tokenizer": {
"type": "<tokenizer-type>"
},
"tokenFilters": [ <list-of-token-filters> ]
}
]

自定义分析器具有以下属性:

属性
类型
说明
必需?

name

字符串

自定义分析器的名称。名称在索引中必须唯一,并且不能以下列任何字符串开头:

  • lucene.

  • builtin.

  • mongodb.

charFilters

对象列表

包含零个或多个字符筛选器的数组。

字符筛选器按照字符逐个检查文本,并执行筛选操作。

要了解更多信息,请参阅字符过滤器。

no

tokenizer

对象

用于创建令牌的分词器。

分析器使用分词器将文本块拆分为组或词元,以便编制索引。

如要了解更多信息,请参阅分词器。

tokenFilters

对象列表

包含零个或多个词元筛选器的数组。

词元筛选器执行以下操作:

  • 提取词干,这会将相关词语(例如“talking”、“talked”和“talks”)缩减为词根“talk”。

  • 日志校订,删除公共文档中的敏感信息。

To learn more, see Token Filters for Custom Analyzers.

no

The Atlas UI Visual Editor includes the option to choose between the following common-use templates to help you get started with building your custom analyzer:

  • 电子邮件解析器 - 使用此工具可通过 uaxUrlEmail 分词器对最多 200 个字符的电子邮件地址进行分词。例如,您可以将此分析器应用于示例集合中的 page_updated_by.email 字段。

  • 电话号码 — 使用 regexCaptureGroup 分词器从美国格式的电话号码中创建单个词元。例如,您可以将此分析器应用于示例集合中的 page_updated_by.phone 字段。

  • 破折号分隔的 ID——使用此功能可使用 regexSplit 分词器从连字符分隔的文本中创建标记。例如,您可以将此分析器应用于示例集合中的 message 字段。

您可以使用这些内置的自定义分析器,也可以使用MongoDB Search Visual EditorJSON 编辑器创建自己的自定义分析器。

The Character Filters, Tokenizers, and Token Filters for Custom Analyzers pages contain sample index definitions and query examples for character filters, tokenizers, and token filters. These examples use a sample minutes collection with the following documents:

{
"_id": 1,
"page_updated_by": {
"last_name": "AUERBACH",
"first_name": "Siân",
"email": "auerbach@example.com",
"phone": "(123)-456-7890"
},
"title": "The team's weekly meeting",
"message": "try to siGn-In",
"text": {
"en_US": "<head> This page deals with department meetings.</head>",
"sv_FI": "Den här sidan behandlar avdelningsmöten",
"fr_CA": "Cette page traite des réunions de département"
}
}
{
"_id": 2,
"page_updated_by": {
"last_name": "OHRBACH",
"first_name": "Noël",
"email": "ohrbach@example.com",
"phone": "(123) 456 0987"
},
"title": "The check-in with sales team",
"message": "do not forget to SIGN-IN. See ① for details.",
"text" : {
"en_US": "The head of the sales department spoke first.",
"fa_IR": "ابتدا رئیس بخش فروش صحبت کرد",
"sv_FI": "Först talade chefen för försäljningsavdelningen"
}
}
{
"_id": 3,
"page_updated_by": {
"last_name": "LEWINSKY",
"first_name": "Brièle",
"email": "lewinsky@example.com",
"phone": "(123).456.9870"
},
"title": "The regular board meeting",
"message": "try to sign-in",
"text" : {
"en_US": "<body>We'll head out to the conference room by noon.</body>"
}
}
{
"_id": 4,
"page_updated_by": {
"last_name": "LEVINSKI",
"first_name": "François",
"email": "levinski@example.com",
"phone": "123-456-8907"
},
"title": "The daily huddle on tHe StandUpApp2",
"message": "write down your signature or phone №",
"text" : {
"en_US": "<body>This page has been updated with the items on the agenda.</body>" ,
"es_MX": "La página ha sido actualizada con los puntos de la agenda.",
"pl_PL": "Strona została zaktualizowana o punkty porządku obrad."
}
}

要了解有关创建自己的自定义分析器的更多信息,请参阅以下参考页面:

注意

当您在 Atlas UI 中使用 Visual Editor 添加自定义分析器时,Atlas UI 会在 Custom Analyzers 部分中显示有关分析器的以下详细信息。

名称

标识自定义分析器的标签。

用于

使用自定义分析器的字段。如果自定义分析器不用于分析任何字段,则值为 None

字符筛选器

在自定义分析器中配置的MongoDB Search 字符筛选器。

分词器

在自定义分析器中配置的MongoDB Search分词器。

词元筛选器

在自定义分析器中配置的MongoDB Search 词元筛选器。

操作

可单击的图标,指示可以对自定义分析器执行的操作。

  • 单击 编辑自定义分析器。

  • 单击 删除自定义分析器。