6.IK分词器拓展词库
比如一些行业专业词汇、简单无意义词(例如:的、得、地、是等)、网络流行词、后来形成的词、再或者一些禁忌词(比如:领导人的名字、黄赌毒犯罪等词要排除的)
在es的插件目录下查找配置文件:
找到IKAnalyzer.cfg.xml文件并进行修改:
向stopword.dic文件中添加如下词:
以上修改完成后,需要重启ES。
注意:创建ext.dic文件时候,注意文件的编码格式,最好拷贝 IKAnalyzer.cfg.xml文件进行修改。
使用file命令查看:
POST /_analyze
{
"text":"想白嫖吗?我是比较奥利给的",
"analyzer": "ik_smart"
}
{
"tokens" : [
{
"token" : "想",
"start_offset" : 0,
"end_offset" : 1,
"type" : "CN_CHAR",
"position" : 0
},
{
"token" : "白嫖",
"start_offset" : 1,
"end_offset" : 3,
"type" : "CN_WORD",
"position" : 1
},
{
"token" : "吗",
"start_offset" : 3,
"end_offset" : 4,
"type" : "CN_CHAR",
"position" : 2
},
{
"token" : "我",
"start_offset" : 5,
"end_offset" : 6,
"type" : "CN_CHAR",
"position" : 3
},
{
"token" : "是",
"start_offset" : 6,
"end_offset" : 7,
"type" : "CN_CHAR",
"position" : 4
},
{
"token" : "比较",
"start_offset" : 7,
"end_offset" : 9,
"type" : "CN_WORD",
"position" : 5
},
{
"token" : "奥利给",
"start_offset" : 9,
"end_offset" : 12,
"type" : "CN_WORD",
"position" : 6
}
]
}