当前位置:首页 > 日记本 > 正文内容

elasticsearch各个分词效果测试

zhangchap1年前 (2023-04-01)日记本135
from elasticsearch import Elasticsearch

es = Elasticsearch()

text = "10万左右口碑最好的车 "

# 使用 Elasticsearch 的 standard 分词器分析文本
tokens = es.indices.analyze(index="new_cars",body={'text': text, 'analyzer': 'standard'})

print("使用 standard 分词器分析文本:")
for token in tokens['tokens']:
    print(token['token'])

# 使用 Elasticsearch 的 ik_max_word 分词器分析文本
tokens = es.indices.analyze(index="new_cars",body={'text': text, 'analyzer': 'ik_max_word'})

print("\n使用 ik_max_word 分词器分析文本:")
for token in tokens['tokens']:
    print(token['token'])

# 使用 Elasticsearch 的 ik_smart 分词器分析文本
tokens = es.indices.analyze(index="new_cars",body={'text': text, 'analyzer': 'ik_smart'})

print("\n使用 ik_smart 分词器分析文本:")
for token in tokens['tokens']:
    print(token['token'])


分享给朋友:

相关文章

火狐添加自定义搜索引擎

直接网址搜索自定义添加:https://mycroftproject.com/...

宝塔重启服务器后,Redis就启动不了解决方案

宝塔重启服务器后,Redis就启动不了解决方案

1.更改权限 chown -R redis.redis /www/server/redis/ 2.设置持久化...

Nginx+PHP,PHP如何优化配置?

具体修改FPM配置文件参数: 若你的php日志出现: WARNING: [pool www] seems busy (you may need to increase pm.sta...

python 函数 开启多线程示例

from threading import Thread def readfile(queue:Queue):    &nbs...

python jieba分词

import jieba from jieba.analyse import tfidf words = jieba.lcut('...

python 发布文章 随机分类(choice)

from random import choice catid = choice([5,6]) #choice 函数从列表中随机提取...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。