IK分词器安装使用

下载地址:https://github.com/medcl/elasticsearch-analysis-ik/releases

1)先将其解压,将解压后的elasticsearch文件夹重命名文件夹为ik

2)将ik文件夹拷贝到elasticsearch/plugins 目录下。

3)重新启动,即可加载IK分词器

 

IK分词器测试

 

IK提供了两个分词算法ik_smart ik_max_word
其中 ik_smart 为最少切分,ik_max_word为最细粒度划分
我们分别来试一下

 

1)最小切分:在浏览器地址栏输入地址

 

http://127.0.0.1:9200/_analyze?analyzer=ik_smart&pretty=true&text=我是程序员

 

输出的结果为:

{
"tokens" : [
{
"token" : "我",
"start_offset" : 0,
"end_offset" : 1,
"type" : "CN_CHAR",
"position" : 0
},
{
"token" : "是",
"start_offset" : 1,
"end_offset" : 2,
"type" : "CN_CHAR",
"position" : 1
},
{
"token" : "程序员",
"start_offset" : 2,
"end_offset" : 5,
"type" : "CN_WORD",
"position" : 2
}
]
} 

2)最细切分:在浏览器地址栏输入地址

http://127.0.0.1:9200/_analyze?analyzer=ik_max_word&pretty=true&text=我是程序

输出的结果为:

 

{
"tokens" : [
{
"token" : "我",
"start_offset" : 0,
"end_offset" : 1,
"type" : "CN_CHAR",
"position" : 0
},
{
"token" : "是",
"start_offset" : 1,
"end_offset" : 2,
"type" : "CN_CHAR",
"position" : 1
},
{
"token" : "程序员",
"start_offset" : 2,
"end_offset" : 5,
"type" : "CN_WORD",
"position" : 2
},
{
"token" : "程序",
"start_offset" : 2,
"end_offset" : 4,
"type" : "CN_WORD",
"position" : 3
},
{
"token" : "员",
"start_offset" : 4,
"end_offset" : 5,
"type" : "CN_CHAR",
"position" : 4
}
]
} 

 

自定义词库

步骤:

1)进入elasticsearch/plugins/ik/config目录

2)新建一个my.dic文件,编辑内容:

大威天龙

修改IKAnalyzer.cfg.xml(在ik/config目录下)

<properties>
<comment>IK Analyzer 扩展配置</comment>
<!‐‐用户可以在这里配置自己的扩展字典 ‐‐>
<entry key="ext_dict">my.dic</entry>
<!‐‐用户可以在这里配置自己的扩展停止词字典‐‐>
<entry key="ext_stopwords"></entry>
</properties> 

重新启动elasticsearch,通过浏览器测试分词效果

{
"tokens" : [
{
"token" : "大威天龙",
"start_offset" : 0,
"end_offset" : 4,
"type" : "CN_WORD",
"position" : 0
}
]
} 

 

posted @ 2020-10-22 17:44  弄半天  阅读(369)  评论(0)    收藏  举报