[[hunspell]]
=== Hunspell Stemmer
Elasticsearch provides ((("dictionary stemmers", "Hunspell stemmer")))((("stemming words", "dictionary stemmers", "Hunspell stemmer")))dictionary-based stemming via the
http://bit.ly/1KNFdXI[`hunspell` token filter].
Hunspell http://hunspell.sourceforge.net/[_hunspell.sourceforge.net_] is the
spell checker used by Open Office, LibreOffice, Chrome, Firefox, Thunderbird, and many
other open and closed source projects.
Hunspell dictionaries((("Hunspell stemmer", "obtaining a Hunspell dictionary"))) can be obtained from the following:
* http://extensions.openoffice.org/[_extensions.openoffice.org_]: Download and
unzip the `.oxt` extension file.
* http://mzl.la/157UORf[_addons.mozilla.org_]:
Download and unzip the `.xpi` addon file.
* http://bit.ly/1ygnODR[OpenOffice archive]: Download and unzip the `.zip` file.
A Hunspell dictionary consists of two files with the same base name--such as
`en_US`—but with one of two extensions:
`.dic`::
Contains all the root words, in alphabetical order, plus a code representing
all possible suffixes and prefixes (which collectively are known as _affixes_)
`.aff`::
Contains the actual prefix or suffix transformation for each code listed
in the `.dic` file
==== Installing a Dictionary
The Hunspell token ((("Hunspell stemmer", "installing a dictionary")))filter looks for dictionaries within a dedicated Hunspell
directory, which defaults to `./config/hunspell/`. The `.dic` and `.aff`
files should be placed in a subdirectory whose name represents the language
or locale of the dictionaries. For instance, we could create a Hunspell
stemmer for American English with the following layout:
[source,text]
------------------------------------------------
config/
└ hunspell/ <1>
└ en_US/ <2>
├ en_US.dic
├ en_US.aff
└ settings.yml <3>
------------------------------------------------
<1> The location of the Hunspell directory can be changed by setting
`indices.analysis.hunspell.dictionary.location` in the
`config/elasticsearch.yml` file.
<2> `en_US` will be the name of the locale or `language` that we pass to the
`hunspell` token filter.
<3> Per-language settings file, described in the following section.
==== Per-Language Settings
The `settings.yml` file contains settings((("Hunspell stemmer", "per-language settings"))) that apply to all of the
dictionaries within the language directory, such as these:
[source,yaml]
-------------------------
---
ignore_case: true
strict_affix_parsing: true
-------------------------
The meaning of these settings is as follows:
`ignore_case`::
+
--
Hunspell dictionaries are case sensitive by default: the surname `Booker` is a
different word from the noun `booker`, and so should be stemmed differently. It
may seem like a good idea to use the `hunspell` stemmer in case-sensitive
mode,((("Hunspell stemmer", "using in case insensitive mode"))) but that can complicate things:
* A word at the beginning of a sentence will be capitalized, and thus appear
to be a proper noun.
* The input text may be all uppercase, in which case almost no words will be
found.
* The user may search for names in all lowercase, in which case no capitalized
words will be found.
As a general rule, it is a good idea to set `ignore_case` to `true`.
--
`strict_affix_parsing`::
The quality of dictionaries varies greatly.((("Hunspell stemmer", "strict_affix_parsing"))) Some dictionaries that are
available online have malformed rules in the `.aff` file. By default, Lucene
will throw an exception if it can't parse an affix rule. If you need to deal
with a broken affix file, you can set `strict_affix_parsing` to `false` to tell
Lucene to ignore the broken rules.((("strict_affix_parsing")))
.Custom Dictionaries
***********************************************
If multiple dictionaries (`.dic` files) are placed in the same
directory, ((("Hunspell stemmer", "custom dictionaries")))they will be merged together at load time. This allows you to
tailor the downloaded dictionaries with your own custom word lists:
[source,text]
------------------------------------------------
config/
└ hunspell/
└ en_US/ <1>
├ en_US.dic
├ en_US.aff <2>
├ custom.dic
└ settings.yml
------------------------------------------------
<1> The `custom` and `en_US` dictionaries will be merged.
<2> Multiple `.aff` files are not allowed, as they could use
conflicting rules.
The format of the `.dic` and `.aff` files is discussed in
<<hunspell-dictionary-format>>.
***********************************************
==== Creating a Hunspell Token Filter
Once your dictionaries are installed on all nodes, you can define a `hunspell`
token filter((("Hunspell stemmer", "creating a hunspell token filter"))) that uses them:
[source,json]
------------------------------------------------
PUT /my_index
{
"settings": {
"analysis": {
"filter": {
"en_US": {
"type": "hunspell",
"language": "en_US" <1>
}
},
"analyzer": {
"en_US": {
"tokenizer": "standard",
"filter": [ "lowercase", "en_US" ]
}
}
}
}
}
------------------------------------------------
<1> The `language` has the same name as the directory where
the dictionary lives.
You can test the new analyzer with the `analyze` API,
and compare its output to that of the `english` analyzer:
[source,json]
------------------------------------------------
GET /my_index/_analyze?analyzer=en_US <1>
reorganizes
GET /_analyze?analyzer=english <2>
reorganizes
------------------------------------------------
<1> Returns `organize`
<2> Returns `reorgan`
An interesting property of the `hunspell` stemmer, as can be seen in the
preceding example, is that it can remove prefixes as well as as suffixes. Most
algorithmic stemmers remove suffixes only.
[TIP]
==================================================
Hunspell dictionaries can consume a few megabytes of RAM. Fortunately,
Elasticsearch creates only a single instance of a dictionary per node. All
shards that use the same Hunspell analyzer share the same instance.
==================================================
[[hunspell-dictionary-format]]
==== Hunspell Dictionary Format
While it is not necessary to understand the((("Hunspell stemmer", "Hunspell dictionary format"))) format of a Hunspell dictionary in
order to use the `hunspell` tokenizer, understanding the format will help you
write your own custom dictionaries. It is quite simple.
For instance, in the US English dictionary, the `en_US.dic` file contains an entry for
the word `analyze`, which looks like this:
[source,text]
-----------------------------------
analyze/ADSG
-----------------------------------
The `en_US.aff` file contains the prefix or suffix rules for the `A`, `G`,
`D`, and `S` flags. Each flag consists of a number of rules, only one of
which should match. Each rule has the following format:
[source,text]
-----------------------------------
[type] [flag] [letters to remove] [letters to add] [condition]
-----------------------------------
For instance, the following is suffix (`SFX`) rule `D`. It says that, when a
word ends in a consonant (anything but `a`, `e`, `i`, `o`, or `u`) followed by
a `y`, it can have the `y` removed and `ied` added (for example, `ready` ->
`readied`).
[source,text]
-----------------------------------
SFX D y ied [^aeiou]y
-----------------------------------
The rules for the `A`, `G`, `D`, and `S` flags mentioned previously are as follows:
[source,text]
-----------------------------------
SFX D Y 4
SFX D 0 d e <1>
SFX D y ied [^aeiou]y
SFX D 0 ed [^ey]
SFX D 0 ed [aeiou]y
SFX S Y 4
SFX S y ies [^aeiou]y
SFX S 0 s [aeiou]y
SFX S 0 es [sxzh]
SFX S 0 s [^sxzhy] <2>
SFX G Y 2
SFX G e ing e <3>
SFX G 0 ing [^e]
PFX A Y 1
PFX A 0 re . <4>
-----------------------------------
<1> `analyze` ends in an `e`, so it can become `analyzed` by adding a `d`.
<2> `analyze` does not end in `s`, `x`, `z`, `h`, or `y`, so it can become
`analyzes` by adding an `s`.
<3> `analyze` ends in an `e`, so it can become `analyzing` by removing the `e`
and adding `ing`.
<4> The prefix `re` can be added to form `reanalyze`. This rule can be
combined with the suffix rules to form `reanalyzes`, `reanalyzed`,
`reanalyzing`.
More information about the Hunspell syntax can be found on the http://bit.ly/1ynGhv6[Hunspell documentation site].
- Introduction
- 入門
- 是什么
- 安裝
- API
- 文檔
- 索引
- 搜索
- 聚合
- 小結
- 分布式
- 結語
- 分布式集群
- 空集群
- 集群健康
- 添加索引
- 故障轉移
- 橫向擴展
- 更多擴展
- 應對故障
- 數據
- 文檔
- 索引
- 獲取
- 存在
- 更新
- 創建
- 刪除
- 版本控制
- 局部更新
- Mget
- 批量
- 結語
- 分布式增刪改查
- 路由
- 分片交互
- 新建、索引和刪除
- 檢索
- 局部更新
- 批量請求
- 批量格式
- 搜索
- 空搜索
- 多索引和多類型
- 分頁
- 查詢字符串
- 映射和分析
- 數據類型差異
- 確切值對決全文
- 倒排索引
- 分析
- 映射
- 復合類型
- 結構化查詢
- 請求體查詢
- 結構化查詢
- 查詢與過濾
- 重要的查詢子句
- 過濾查詢
- 驗證查詢
- 結語
- 排序
- 排序
- 字符串排序
- 相關性
- 字段數據
- 分布式搜索
- 查詢階段
- 取回階段
- 搜索選項
- 掃描和滾屏
- 索引管理
- 創建刪除
- 設置
- 配置分析器
- 自定義分析器
- 映射
- 根對象
- 元數據中的source字段
- 元數據中的all字段
- 元數據中的ID字段
- 動態映射
- 自定義動態映射
- 默認映射
- 重建索引
- 別名
- 深入分片
- 使文本可以被搜索
- 動態索引
- 近實時搜索
- 持久化變更
- 合并段
- 結構化搜索
- 查詢準確值
- 組合過濾
- 查詢多個準確值
- 包含,而不是相等
- 范圍
- 處理 Null 值
- 緩存
- 過濾順序
- 全文搜索
- 匹配查詢
- 多詞查詢
- 組合查詢
- 布爾匹配
- 增加子句
- 控制分析
- 關聯失效
- 多字段搜索
- 多重查詢字符串
- 單一查詢字符串
- 最佳字段
- 最佳字段查詢調優
- 多重匹配查詢
- 最多字段查詢
- 跨字段對象查詢
- 以字段為中心查詢
- 全字段查詢
- 跨字段查詢
- 精確查詢
- 模糊匹配
- Phrase matching
- Slop
- Multi value fields
- Scoring
- Relevance
- Performance
- Shingles
- Partial_Matching
- Postcodes
- Prefix query
- Wildcard Regexp
- Match phrase prefix
- Index time
- Ngram intro
- Search as you type
- Compound words
- Relevance
- Scoring theory
- Practical scoring
- Query time boosting
- Query scoring
- Not quite not
- Ignoring TFIDF
- Function score query
- Popularity
- Boosting filtered subsets
- Random scoring
- Decay functions
- Pluggable similarities
- Conclusion
- Language intro
- Intro
- Using
- Configuring
- Language pitfalls
- One language per doc
- One language per field
- Mixed language fields
- Conclusion
- Identifying words
- Intro
- Standard analyzer
- Standard tokenizer
- ICU plugin
- ICU tokenizer
- Tidying text
- Token normalization
- Intro
- Lowercasing
- Removing diacritics
- Unicode world
- Case folding
- Character folding
- Sorting and collations
- Stemming
- Intro
- Algorithmic stemmers
- Dictionary stemmers
- Hunspell stemmer
- Choosing a stemmer
- Controlling stemming
- Stemming in situ
- Stopwords
- Intro
- Using stopwords
- Stopwords and performance
- Divide and conquer
- Phrase queries
- Common grams
- Relevance
- Synonyms
- Intro
- Using synonyms
- Synonym formats
- Expand contract
- Analysis chain
- Multi word synonyms
- Symbol synonyms
- Fuzzy matching
- Intro
- Fuzziness
- Fuzzy query
- Fuzzy match query
- Scoring fuzziness
- Phonetic matching
- Aggregations
- overview
- circuit breaker fd settings
- filtering
- facets
- docvalues
- eager
- breadth vs depth
- Conclusion
- concepts buckets
- basic example
- add metric
- nested bucket
- extra metrics
- bucket metric list
- histogram
- date histogram
- scope
- filtering
- sorting ordering
- approx intro
- cardinality
- percentiles
- sigterms intro
- sigterms
- fielddata
- analyzed vs not
- 地理坐標點
- 地理坐標點
- 通過地理坐標點過濾
- 地理坐標盒模型過濾器
- 地理距離過濾器
- 緩存地理位置過濾器
- 減少內存占用
- 按距離排序
- Geohashe
- Geohashe
- Geohashe映射
- Geohash單元過濾器
- 地理位置聚合
- 地理位置聚合
- 按距離聚合
- Geohash單元聚合器
- 范圍(邊界)聚合器
- 地理形狀
- 地理形狀
- 映射地理形狀
- 索引地理形狀
- 查詢地理形狀
- 在查詢中使用已索引的形狀
- 地理形狀的過濾與緩存
- 關系
- 關系
- 應用級別的Join操作
- 扁平化你的數據
- Top hits
- Concurrency
- Concurrency solutions
- 嵌套
- 嵌套對象
- 嵌套映射
- 嵌套查詢
- 嵌套排序
- 嵌套集合
- Parent Child
- Parent child
- Indexing parent child
- Has child
- Has parent
- Children agg
- Grandparents
- Practical considerations
- Scaling
- Shard
- Overallocation
- Kagillion shards
- Capacity planning
- Replica shards
- Multiple indices
- Index per timeframe
- Index templates
- Retiring data
- Index per user
- Shared index
- Faking it
- One big user
- Scale is not infinite
- Cluster Admin
- Marvel
- Health
- Node stats
- Other stats
- Deployment
- hardware
- other
- config
- dont touch
- heap
- file descriptors
- conclusion
- cluster settings
- Post Deployment
- dynamic settings
- logging
- indexing perf
- rolling restart
- backup
- restore
- conclusion