Overview
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> ] } ]
属性
自定义分析器具有以下属性:
属性 | 类型 | 说明 | 必需? |
|---|---|---|---|
| 字符串 | 自定义分析器的名称。名称在索引中必须唯一,并且不能以下列任何字符串开头:
| 是 |
| 对象列表 | no | |
| 对象 | 是 | |
| 对象列表 | 包含零个或多个词元筛选器的数组。 词元筛选器执行以下操作:
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 Editor 或 JSON 编辑器创建自己的自定义分析器。
示例集合
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 部分中显示有关分析器的以下详细信息。