发布了一个基于jieba分词的ElasticSearch插件
2024-08-21 15:20:58
github地址: https://github.com/hongfuli/elasticsearch-analysis-jieba
基于 jieba 的 elasticsearch 中文分词插件。
集成到ElasticSearch
git clone git@github.com:hongfuli/elasticsearch-analysis-jieba.git
cd elasticsearch-analysis-jieba
mvn package
把release/elasticsearch-analysis-jieba-{version}.zip文件解压到 elasticsearch 的 plugins 目录下,重启elasticsearch即可。
直接使用Tokenizer分词
可直接使用 com.github.hongfuli.jieba.Tokenizer
对文本字符进行分词,方法参数完全和 jieba python 一致。
imort com.github.hongfuli.jieba.Tokenizer
Tokenizer t = new Tokenizer();
t.cut("这是一个伸手不见五指的黑夜。我叫孙悟空,我爱北京,我爱Python和C++。", false, true);
集成到Lucene
import com.github.hongfuli.jieba.lucene.JiebaAnalyzer;
Analyzer analyzer = new JiebaAnalyzer();
try(TokenStream ts = analyzer.tokenStream("field", "这是一个伸手不见五指的黑夜。我叫孙悟空,我爱北京,我爱Python和C++。")) {
StringBuilder b = new StringBuilder();
CharTermAttribute termAtt = ts.getAttribute(CharTermAttribute.class);
PositionIncrementAttribute posIncAtt = ts.getAttribute(PositionIncrementAttribute.class);
PositionLengthAttribute posLengthAtt = ts.getAttribute(PositionLengthAttribute.class);
OffsetAttribute offsetAtt = ts.getAttribute(OffsetAttribute.class);
assertNotNull(offsetAtt);
ts.reset();
int pos = -1;
while (ts.incrementToken()) {
pos += posIncAtt.getPositionIncrement();
b.append(termAtt);
b.append(" at pos=");
b.append(pos);
if (posLengthAtt != null) {
b.append(" to pos=");
b.append(pos + posLengthAtt.getPositionLength());
}
b.append(" offsets=");
b.append(offsetAtt.startOffset());
b.append('-');
b.append(offsetAtt.endOffset());
b.append('\n');
}
ts.end();
return b.toString();
}
最新文章
- DPA 9.1.85 升级到DPA 10.0.352流程
- [WebService]之DTD
- MSSQLSERVER数据库- 打开表出现目录名无效
- es6小技巧
- 常用Linux VPS/服务器SSH连接工具 - Xshell下载与使用
- Coursera, Machine Learning, Neural Networks: Representation - week4/5
- Dubbox:来自当当网的SOA服务框架
- Java知多少(90)菜单
- PHP操作数据库函数比较
- Linux服务器部署系列之七—OpenLDAP篇
- 2017-2018-2 20155315《网络对抗技术》Exp4:恶意代码分析
- Python :random 随机数生成
- MySQL Group Replication 介绍
- 洛谷P1528 切蛋糕 [搜索,二分答案]
- 使用postman实现半自动化
- ccf201703-2 STLlist
- SQL Server 使用分区函数实现查询优化
- Office加载项对Excel进行读写操作
- scrapy爬虫 函数间传值简易教程
- A norm is a function. 范数是函数。
热门文章
- redis介绍 (8) window 下redis的集群(cluster命令)
- (网页)the server responded with a status of 403 (Forbidden)
- 消除TortoiseSVN 检出到(checkout)桌面上显示一堆问号
- [Kali_Debian] 清除无用的库文件(清理系统,洁癖专用)-布布扣-bubuko.com - Google Chrome
- 前端使用 validate , 根据条件进行动态的验证添加
- Parameter infoDTOs of type T from private T com.ListVO.setInfoDTOs is not resolvable to a concrete type.
- 【17】有关python面向对象编程的提高【多继承、多态、类属性、动态添加与限制添加属性与方法、@property】
- css实现不定高度的元素垂直居中问题
- Android中消息系统模型和Handler Looper
- mini2440裸机试炼之—RTC闹钟中断,节拍中断