当前位置:网站首页>IK分词器
IK分词器
2022-06-26 18:25:00 【cc_南柯一梦】
1、IK分词器有两种分词模式:ik_max_word和ik_smart模式。
【1】ik_max_word (常用) 会将文本做最细粒度的拆分
POST _analyze
{
"analyzer": "ik_max_word",
"text": "北京市长春桥地铁站"
} 
【2】ik_smart会做最粗粒度的拆分
POST _analyze
{
"analyzer": "ik_smart",
"text": "北京市长春桥地铁站"
} 
2、扩展词典使用
扩展词就是不想让那些词被分开,让他们组成一个此,比如长春桥
1、自定义扩展词库
进入到config/analysis-ik(插件安装方式)或/usr/elasticsearch/plugins/analysis-ik/config/目录下新增自定义词典
vi cc_ext_dict.dic 输入:长春桥

2、自定义的扩展词典文件添加到IKAnalyzer.cfg.xml配置中
vi IKAnalyzer.cfg.xml

3、重启es
/usr/elasticsearch/bin/elasticsearch
3、停用词典使用
停用词就是在文本中出现频率很高,但是对语义产生不了多大的影响,比如中文的“的、哦、了、呢”等,这些词称为停用词。一般经常会被过滤掉不会进行索引
1、自定义停用词库
进入到config/analysis-ik(插件安装方式)或/usr/elasticsearch/plugins/analysis-ik/config/目录下新增自定义词典
vi cc_stop_dict.dic 输入 的、哦、了、呢

2、添加到IKAnalyzer.cfg.xml配置中

3、重启es
/usr/elasticsearch/bin/elasticsearch
4、同义词典使用
意思相同的词,在搜索时应该同时查出来,比如“馒头”和“馍”,这种情况叫做同义词查询
注意:扩展词和停用词时在索引的时候使用,同义词是检索的时候
1、创建synonym.txt
vi synonym.txt 输入同义词

2、重启es
/usr/elasticsearch/bin/elasticsearch
3、使用是指定synonym.text
前缀路径为:/usr/elasticsearch/config/
analysis:为自己创建的目录

PUT /cc003
{
"settings": {
"analysis": {
"filter": {
"word_sync": {
"type": "synonym",
"synonyms_path": "analysis/synonym.txt"
}
},
"analyzer": {
"ik_sync_max_word": {
"filter": [
"word_sync"
],
"type": "custom",
"tokenizer": "ik_max_word"
},"ik_sync_smart": {
"filter": [
"word_sync"
],
"type": "custom",
"tokenizer": "ik_smart"
}
}
}
},
"mappings": {
"properties": {
"name": {
"type": "text",
"analyzer": "ik_sync_max_word",
"search_analyzer": "ik_sync_max_word"
}
}
}
}4、添加内容
POST /cc003/_doc/1
{
"name":"馒头你们哪里叫什么"
}5、查询
POST /cc003/_doc/_search
{
"query":{
"match":{
"name": "馍"
}
}
} 
边栏推荐
猜你喜欢
随机推荐
Let torch cuda. is_ Experience of available() changing from false to true
Leetcode 128 longest continuous sequence
Idea collection code, quickly open favorites collection window
Publish message publishers and subscribe message subscribers of ROS
成功解决之微服务@Value获取配置文件乱码问题
Numpy之matplotlib
爬取豆瓣读书Top250,导入sqlist数据库(或excel表格)中
Crawl Douban to read top250 and import it into SqList database (or excel table)
Map和List<Map>转相应的对象
Introduction to Ethereum Technology Architecture
读书笔记:《过程咨询 III》
刻录光盘的程序步骤
Create a time blocker yourself
Soft test preparation multimedia system
Insert string B into string A. how many insertion methods can make the new string a palindrome string
临时关闭MySQL缓存
ros::spinOnce()和ros::spin()的使用和区别
System table SQLite of SQLite database_ master
【Kubernetes】Kubernetes 原理剖析与实战应用(更新中)
Microservice architecture








