Lucene索引库的维护功能实现
索引库的维护
索引库的添加
步骤
向索引库中添加document对象。
第一步:先创建一个indexwriter对象
第二步:创建一个document对象
第三步:把document对象写入索引库
第四步:关闭indexwriter。
- 代码实现
//添加索引
@Test
public void addDocument() throws Exception {//索引库存放路径Directory directory = FSDirectory.open(new File("D:\\temp\\0108\\index"));IndexWriterConfig config = new IndexWriterConfig(Version.LATEST, new IKAnalyzer());//创建一个indexwriter对象IndexWriter indexWriter = new IndexWriter(directory, config);//创建一个Document对象Document document = new Document();//向document对象中添加域。//不同的document可以有不同的域,同一个document可以有相同的域。document.add(new TextField("filename", "新添加的文档", Store.YES));document.add(new TextField("content", "新添加的文档的内容", Store.NO));document.add(new TextField("content", "新添加的文档的内容第二个content", Store.YES));document.add(new TextField("content1", "新添加的文档的内容要能看到", Store.YES));//添加文档到索引库indexWriter.addDocument(document);//关闭indexwriterindexWriter.close();}
- 索引库删除
- 删除全部
//删除全部索引
@Test
public void deleteAllIndex() throws Exception {IndexWriter indexWriter = getIndexWriter();//删除全部索引indexWriter.deleteAll();//关闭indexwriterindexWriter.close();
}
说明:将索引目录的索引信息全部删除,直接彻底删除,无法恢复。
此方法慎用!!
- 指定查询条件删除
//根据查询条件删除索引
@Test
public void deleteIndexByQuery() throws Exception {IndexWriter indexWriter = getIndexWriter();//创建一个查询条件Query query = new TermQuery(new Term("filename", "apache"));//根据查询条件删除indexWriter.deleteDocuments(query);//关闭indexwriterindexWriter.close();
}
- 索引库的修改
原理就是先删除后添加。
//修改索引库
@Test
public void updateIndex() throws Exception {IndexWriter indexWriter = getIndexWriter();//创建一个Document对象Document document = new Document();//向document对象中添加域。//不同的document可以有不同的域,同一个document可以有相同的域。document.add(new TextField("filename", "要更新的文档", Store.YES));document.add(new TextField("content", "2013年11月18日 - Lucene 简介 Lucene 是一个基于 Java 的全文信息检索工具包,它不是一个完整的搜索应用程序,而是为你的应用程序提供索引和搜索功能。", Store.YES));indexWriter.updateDocument(new Term("content", "java"), document);//关闭indexWriterindexWriter.close();
}
Lucene索引库的维护功能实现相关推荐
- 遍历lucene索引库的字段名
更多个人技术分享,请访问http://www.derekchou.com try {Collection<String> fn = null;String[] idxFields = nu ...
- lucene索引搜索_Lucene –快速添加索引和搜索功能
lucene索引搜索 什么是Lucene? Apache LuceneTM是完全用Java编写的高性能,功能齐全的文本搜索引擎库. 它是一项适用于几乎所有需要全文本搜索的应用程序的技术,尤其是跨平台. ...
- 【示例】Lucene查询索引库编程步骤
Lucene查询索引库编程步骤
- 【示例】Lucene创建索引库编程步骤
[示例]Lucene创建索引库编程步骤
- 2.Lucene3.6.2包介绍,第一个Lucene案例介绍,查看索引信息的工具lukeall介绍,Luke查看的索引库内容,索引查找过程
1 Lucen目录介绍 2 lucene-core-3.6.2.jar是lucene开发核心jar包 contrib 目录存放,包含一些扩展jar包 3 案例 建立第一个Lucene项目 ...
- elastic 索引库_使用Elastic Job Agents自动执行Azure SQL数据库索引维护
elastic 索引库 In this article, I am going to explain how we can automate the index and statistics main ...
- Elasticsearch实战-实现Hotel索引库的自动补全、拼音搜索功能
一.实现思路 1.修改hotel索引库结构,设置自定义拼音分词器 2.修改索引库的name.all字段,使用自定义分词器 3.索引库添加一个新字段suggestion,类型为completion类型, ...
- 2021年大数据ELK(三):Lucene全文检索库介绍
全网最详细的大数据ELK文章系列,强烈建议收藏加关注! 新文章都已经列出历史文章目录,帮助大家回顾前面的知识重点. 目录 系列历史文章 一.什么是全文检索 1.结构化数据与非结构化数据 2.搜索结构化 ...
- 3.5 实例讲解Lucene索引的结构设计
3.2节我们已经运行了一个Lucene建立索引的小程序,这一节我们就以这个小程序为例讲解一下Lucene建立索引的过程. 1 import java.nio.charset.StandardChars ...
最新文章
- 0.38秒!MIT 机器人还原3阶魔方的时间再破记录
- PowerDesigner反向生成物理数据模型
- 干货|如何在无回显时渗透
- 中科院等发布《2019研究前沿》
- 微型计算机c320r3怎么拆,联想C320一体机拆机图解
- 什么是JDK JRE JVM?
- 资质申报 - 系统集成企业资质等级评定条件实施细则
- R-CNN解读+代码梳理
- 【bug解决】上传图片后,取消这次上传 再次执行上传,上次的图片还存在
- 802d简明调试手册_802d简明调试手册.pdf
- 介绍几种电路上常用的塑料插接件(1)
- Alist简单使用指南
- 原生Android手机管家,腾讯手机管家Android 7.13版更新 你的专属管家已上线
- 计算机对水利方面的影响,计算机技术对于水利工程信息化系统的优化作用
- 华为OD机试真题2023(JavaScript)
- STM32 ADC采样
- 【Tableau 05】表连接方式(四)关系 Relationship
- vue noVNC实现远程桌面连接
- 随笔-能够让我们感觉美好的只是回忆而已
- 02.设置windows密码重设盘
热门文章
- 【必须收藏】那些酷炫的深度学习网络图怎么画出来的?
- 圆形的CNN卷积核?华中科大清华黄高团队康奈尔提出圆形卷积,进一步提升卷积结构性能!
- ECCV 2018 | Bi-box行人检测:‘行人遮挡’为几何?
- Python入门实战题目
- 预告丨大型出海知识盛宴,邀您一起 enjoy !
- IM群聊消息如此复杂,如何保证不丢不重?
- 正则(身份证,手机号,邮箱,正整数)
- 9.kotlin安卓实践课程-用kotlin写第一个fragment的recyclerView的adapter具体实现
- Silverlight C# 游戏开发:游戏循环体的五种设计方式
- 怎么样Windows7在配置ASPserverIIS