Link Search Menu Expand Document Documentation Menu

字典解复合词元过滤器

dictionary_decompounder 词元过滤器用于根据预定义字典将复合词拆分为其组成部分。此过滤器对于德语、荷兰语或芬兰语等复合词常见的语言特别有用,因为将其拆分可以提高搜索相关性。dictionary_decompounder 词元过滤器根据已知词列表确定每个词元(单词)是否可以拆分为更小的词元。如果词元可以拆分为已知词,则过滤器会为该词元生成子词元。

参数

dictionary_decompounder 词元过滤器具有以下参数。

参数 必需/可选 数据类型 描述
word_list 除非配置了 word_list_path,否则为必填项 字符串数组 过滤器用于拆分复合词的字典。
word_list_path 除非配置了 word_list,否则为必填项 字符串 包含字典词的文本文件的文件路径。接受绝对路径或相对于 config 目录的相对路径。字典文件必须采用 UTF-8 编码,并且每个词必须单独列一行。
min_word_size 可选 整数 将考虑拆分的整个复合词的最小长度。如果复合词短于此值,则不进行拆分。默认值为 5
min_subword_size 可选 整数 任何子词的最小长度。如果子词短于此值,则不包含在输出中。默认值为 2
max_subword_size 可选 整数 任何子词的最大长度。如果子词长于此值,则不包含在输出中。默认值为 15
only_longest_match 可选 布尔型 如果设置为 true,则只返回最长的匹配子词。默认值为 false

示例

以下示例请求创建一个名为 decompound_example 的新索引,并使用 dictionary_decompounder 过滤器配置分析器

PUT /decompound_example
{
  "settings": {
    "analysis": {
      "filter": {
        "my_dictionary_decompounder": {
          "type": "dictionary_decompounder",
          "word_list": ["slow", "green", "turtle"]
        }
      },
      "analyzer": {
        "my_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": ["lowercase", "my_dictionary_decompounder"]
        }
      }
    }
  }
}

生成的词元

使用以下请求检查使用该分析器生成的词元

POST /decompound_example/_analyze
{
  "analyzer": "my_analyzer",
  "text": "slowgreenturtleswim"
}

响应包含生成的词元

{
  "tokens": [
    {
      "token": "slowgreenturtleswim",
      "start_offset": 0,
      "end_offset": 19,
      "type": "<ALPHANUM>",
      "position": 0
    },
    {
      "token": "slow",
      "start_offset": 0,
      "end_offset": 19,
      "type": "<ALPHANUM>",
      "position": 0
    },
    {
      "token": "green",
      "start_offset": 0,
      "end_offset": 19,
      "type": "<ALPHANUM>",
      "position": 0
    },
    {
      "token": "turtle",
      "start_offset": 0,
      "end_offset": 19,
      "type": "<ALPHANUM>",
      "position": 0
    }
  ]
}
剩余 350 字符

有问题?

想要贡献?