1. Hunspell Token Filter(Hunspell 词元过滤器)
原文链接 :https://www.elastic.co/guide/en/elasticsearch/reference/5.4/analysis-hunspell-tokenfilter.html
译文链接 : http://www.apache.wiki/pages/viewpage.action?pageId=10028041
1.1. 简述
Hunspell过滤器是Hunspell的基础。Hunspell字典将从文件系统上的专用hunspell目录( <path.conf>/hunspell
)中<path.conf>/hunspell
。 预期每个字典都有自己的目录,以其关联的语言环境(语言)命名。 这个字典目录预计会保存一个*.aff
和一个或多个*.dic
文件(所有这些文件将自动被读取)。 例如,假设使用默认的hunspell位置,以下目录布局将定义en_US
字典:
- conf
|-- hunspell
| |-- en_US
| | |-- en_US.dic
| | |-- en_US.aff
1.2. 参数
每个字典都可以进行一个设置:
ignore_case
如果为true,字典匹配将不区分大小写(默认为false )
这个设置可以在elasticsearch.yml
使用全局elasticsearch.yml
indices.analysis.hunspell.dictionary.ignore_case
或指定特定字典:
indices.analysis.hunspell.dictionary.en_US.ignore_case
。
还可以在保存这些设置的settings.yml
目录下添加settings.yml
文件(这将覆盖在elasticsearch.yml
定义的任何其他设置)。
可以通过配置分析设置来使用hunspell过滤器:
{
"analysis" : {
"analyzer" : {
"en" : {
"tokenizer" : "standard",
"filter" : [ "lowercase", "en_US" ]
}
},
"filter" : {
"en_US" : {
"type" : "hunspell",
"locale" : "en_US",
"dedup" : true
}
}
}
}
hunspell过滤器接受四个选项:
locale
此过滤器的区域设置。 如果这没有设置,则使用lang或者language来代替它们,因此必须设置其中一个。
dictionary
字典的名称 您的hunspell字典的路径应通过indices.analysis.hunspell.dictionary.location 。
dedup
如果需要返回单条结果,则需要将其设置为true 。 默认为true 。
longest_only
如果只返回最长的结果,请将其设置为true 。 默认为false :返回所有可能的结果。
与(基于算法的) snowball stemmers(雪球词干分析器)相反,这是基于词典查找的,因此词干的质量由词典的质量决定。
加载字典
默认情况下,当节点启动时,将为该字典检查默认的Hunspell目录( config/hunspell/
),并自动加载任何字典。
通过在配置文件indices.analysis.hunspell.dictionary.lazy
设置为true
,可以将字典加载实际使用。
1.3. 参考
Hunspell是一个拼写检查器和形态分析器,专为具有丰富形态和复杂的字复合和字符编码的语言而设计。
- 维基百科, http://en.wikipedia.org/wiki/Hunspell
- 源代码, http://hunspell.sourceforge.net/
- 开放办公室Hunspell字典, http://wiki.openoffice.org/wiki/Dictionaries
- Mozilla Hunspell字典, https://addons.mozilla.org/en-US/firefox/language-tools/
- Chromium Hunspell字典, http://src.chromium.org/viewvc/chrome/trunk/deps/third_party/hunspell_dictionaries/