安裝IK分詞器
1下載源碼:
https://github.com/medcl/elasticsearch-analysis-ik此頁面有一個鏈接“DownloadZIP”,點擊該鏈接即可下載源碼。
2編譯源碼
該源碼是通過maven管理的,通過pom文件即可導入到現有eclipse工程中。編譯獲得elasticsearch-analysis-ik-1.2.9.jar。
在plugins目錄下建analysis-ik目錄,並把上述elasticsearch-analysis-ik-1.2.9.jar拷入。
3 config目錄
源碼中有一個config目錄,對應elasticsearch-1.4.2下的config目錄。
首先把源碼的config目錄下的ik目錄拷貝到elasticsearch-1.4.2\config下。
源碼的confi目錄下還有一個elasticsearch.yml,把該文件最底下的修改copy到elasticsearch-1.4.2\config下的elasticsearch.yml中。源碼中的logging.yml不做處理。
index:
analysis:
analyzer:
ik:
alias: [news_analyzer_ik,ik_analyzer]
type: org.elasticsearch.index.analysis.IkAnalyzerProvider
index.analysis.analyzer.default.type :"ik"
4 lib目錄
在.m2下搜“httpclient-4.3.5.jar”和“httpcore-4.3.2.jar”,拷到elasticsearch-1.4.2\lib下。
---------------------------
同義詞:
在config目錄下沒有看到同義詞詞典。IK不支持同義詞分詞?
查了下,下面鏈接說如何通過filter支持同義詞,不過版本是1.3。有空再看。
權威指南里的同義詞說明,不過沒看到外鏈文件。
http://www.elastic.co/guide/en/elasticsearch/guide/current/synonyms.html
安裝mmseg分詞器
過程跟安裝IK分詞器是類似的。區別:
1 plugins目錄下建的是mmseg目錄;
2 elasticsearch.yml中添加了源碼中帶的設置之後,啓動後報:
“java.lang.ClassNotFoundException: org.elasticsearch.index.analysis.htmlstrip.HtmlStripTokenFilterFactory”
查了google,也沒找到原因,猜是html_strip相關的問題。注掉elasticsearch.yml中char_filter相關的行後,就好了。
不過char_filter這麼寫是教程裏的呀。http://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-custom-analyzer.html
------------------------
mmseg的分詞效果。解析“中華人民共和國國歌”,比IK少了4個詞。mmseg詞庫不全。
{
"tokens": [
{
"token": "中華",
"start_offset": 2,
"end_offset": 4,
"type": "word",
"position": 1
},
{
"token": "華人",
"start_offset": 3,
"end_offset": 5,
"type": "word",
"position": 2
},
{
"token": "人民",
"start_offset": 4,
"end_offset": 6,
"type": "word",
"position": 3
},
{
"token": "共和",
"start_offset": 6,
"end_offset": 8,
"type": "word",
"position": 4
},
{
"token": "國",
"start_offset": 8,
"end_offset": 9,
"type": "word",
"position": 5
},
{
"token": "國歌",
"start_offset": 9,
"end_offset": 11,
"type": "word",
"position": 6
}
]
}