当前位置:网站首页>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": "馍"
}
}
} 
边栏推荐
- ROS查询话题具体内容常用指令
- CD-CompactDisk
- Request method 'POST' not supported
- PC end records 515 ground sweeping robot /scan data
- 成功解决之idea引用Lombok的@Slf4j后无法正常使用log
- Union, intersection and difference operations in SQL
- Soft test preparation multimedia system
- Boyun, standing at the forefront of China's container industry
- xlua获取ugui的button注册click事件
- Padding percentage operation
猜你喜欢
随机推荐
NFTGameFi链游系统开发详解方案丨链游系统开发原理解析
Numpy之matplotlib
LeetCode 面试题29 顺时针打印矩阵
Binary search-2
Clion compiling catkin_ WS (short for ROS workspace package) loads cmakelists Txt problems
项目实战五:搭建ELk日志收集系统
CD-CompactDisk
将字符串B插入字符串A,有多少种插入办法可以使新串是一个回文串
JVM entry Door (1)
Get and set settings in 26class
DAPP丨LP单双币流动性质押挖矿系统开发原理分析及源码
in和exsits、count(*)查询优化
预编译处理指令中的条件编译
Summary of alter operation in SQL
ROS查询话题具体内容常用指令
Using recursion to find all gray codes with n bits
CLion断点单步调试
你了解如何比较两个对象吗
Paging query and join Association query optimization
读书笔记:《过程咨询 III》









