lucene6.0版本

场景一:第一次启动程序索引库为空抛出异常

最近在写lucene发现利用lucene6.0版本时候如果索引库为空构建indexWriter,代码如下:

IndexWrterConfig config = new IndexWriterConfig(analyzer);
IndexWriter indexWriter = new IndexWriter(config);
IndexReader reader = IndexReader.open(directory); 

程序顺序执行上面代码块是正常的,但是调用iIndexReader reader = IndexReader.open(directory); 后报错“no segments* file”。

解决办法:在获取indexWriter对象后手动commit一次建立索引库版本信息,最终问题解决!代码如下:

IndexWrterConfig config = new IndexWriterConfig(analyzer);
IndexWriter indexWriter = new IndexWriter(config);
indexWriter.commit();//手动提交一次
IndexReader reader = IndexReader.open(directory); 

场景二:提交文档并提交以后再次启动抛出异常

异常原因:可能是文件读写异常终止以后,程序再次启动时候,lucene对索引库进行合并读取操作,信息缺失,索引库读取和合并操作失败。

解决办法:在indexWriter.commit()后没有调用indexWriter.close()方法,此时文档内容为空

场景三:程序异常终止(手动杀死进程,造成索引库未写入全)

解决办法:可以用如下代码修复索引,会帮你删除损坏的索引文件

/*** @param source 索引源* @param dest 索引目标* @param indexWriterConfig 配置相关*/
public static void recoveryIndex(String source, String dest, IndexWriterConfig indexWriterConfig) {IndexWriter indexWriter = null;try {indexWriter = new IndexWriter(FSDirectory.open(Paths.get(dest)), indexWriterConfig);} catch (IOException e) {log.error("", e);} finally {//说明IndexWriter正常打开了,无需恢复if (indexWriter != null && indexWriter.isOpen()) {try {indexWriter.close();} catch (IOException e) {log.error("", e);}} else {//说明IndexWriter已经无法打开,使用备份恢复索引//此处简单操作,先清空损坏的索引文件目录,如果索引特别大,可以比对每个文件,不必全部删除  try {FileUtils.deleteDirectory(new File(dest));FileUtils.copyDirectory(new File(source), new File(dest));} catch(IOException e){log.error("", e);//使用备份恢复出错,那么就使用最后一招修复索引log.info("Check index {} now!", dest);try {IndexUtils.checkIndex(dest);} catch (IOException | InterruptedException e1) {log.error("Check index error!", e1);}}}
}

lucene8.2版本

场景一:第一次启动程序索引库为空抛出异常

第一次启动索引库未空的程序,程序抛出异常代码如下:

     IndexWriterConfig writerConfig = new IndexWriterConfig(analyzer);IndexWriter indexWriter = new IndexWriter(dic,writerConfig);

解决方法:直接在IndexWriterConfig参数中配置索引库不存在时候创建即可,代码如下:

     IndexWriterConfig writerConfig = new IndexWriterConfig(analyzer);writerConfig.setOpenMode(OpenMode.CREATE_OR_APPEND);//解决IndexWriter indexWriter = new IndexWriter(dic,writerConfig);IndexReader reader = DirectoryReader.open(dic);

说明:查询了http://lucene.apache.org/core/8_2_0/core/index.html文档,发现OpenMode有以下三个参数:

APPEND 索引库版本信息(索引库是否为空)存在则追加操作
CREATE 不管索引版本信息是否存在重新创建索引库
CREATE_OR_APPEND 如果索引库存在进行追加,不存在会自动创建

参考博客:

  1. https://blog.csdn.net/jinwufeiyang/article/details/51817822
  2. https://blog.csdn.net/P397226804/article/details/69396370
  3. http://codepub.cn/2016/06/24/Lucene-6-0-in-action-the-index-of-hot-backup-and-recovery/  (该博主是阿里大牛,想学lucene可以看它文章,受益匪浅)

no segments* file found in SimpleFSDirectory问题总结相关推荐

  1. no segments* file found in org.apache.lucene.store.SimpleFSDirectory

    建立好文件索引后,再执行搜索个过程中出现了这个异常: rg.apache.lucene.index.IndexNotFoundException: no segments* file found in ...

  2. lucene 索引出错 no segments* file found in org.apache.lucene.store.MMapDirectory

    创建第一个lucene索引后,搜索出错: org.apache.lucene.index.IndexNotFoundException: no segments* file found in org. ...

  3. 餐中餐(5)Lucene--存储文件加载(Part 1: Segments加载)

    note: 代码版本:Lucene 最新版本 --> https://github.com/apache/lucene 文章目录 Graph Abstract: 1. Index –> S ...

  4. 全文检索Lucene

    全文检索Lucene lucene入门 ​ 什么是lucene ​ Lucene的作用 ​ 使用场景 ​ 优点和缺点 lucene应用 ​ 索引流程 ​ 搜索流程 ​ field域的使用 ​ 索引库维 ...

  5. 全文检索 Lucene

    全文检索 Lucene 网上学习黑马课程后,在原有笔记的基础上进行总结 课程计划 lucene入门 什么是lucene Lucene的作用 使用场景 优点和缺点 lucene应用 索引流程 搜索流程 ...

  6. lucene ---- 黑马教程

    https://www.bilibili.com/video/BV1eJ411q7nw/?spm_id_from=333.337.search-card.all.click 文章目录 全文检索Luce ...

  7. lucene-solr本地调试方法

    1.下载并编译lucene-solr的源代码,并导入 eclipse sts等 2.修改SolrDispatchFilter的solr.solr.home属性,我们这里将其直接修改为一个本地绝对路径, ...

  8. lucene源码分析(7)Analyzer分析

    1.Analyzer的使用 Analyzer使用在IndexWriter的构造方法 /*** Constructs a new IndexWriter per the settings given i ...

  9. Windows上PHP扩展的实现,部署及应用

    2019独角兽企业重金招聘Python工程师标准>>> PHP对扩展的编写要求非常严格.如果没有按照官方文档,使用对应的PHP版本,PHP源码版本,以及Visual Studio版本 ...

最新文章

  1. pytorch topk()
  2. hana::detail::variadic::foldl1用法的测试程序
  3. flink 不设置水印_区分理解Flink水印延迟与窗口允许延迟的概念
  4. AjaxAtlas技术团队[公告]:请大家清理自己发布在团队页面上的post!
  5. mysql文章列表_MySQL-分享文章列表 - Su的博客
  6. 一步一步教你如何安装Dart
  7. 正弦波表(应该还会补充)
  8. MS Sql server 日期转换为特定字符串格式
  9. 【最新】2018年注册测绘师考试测绘案例分析真题及参考答案
  10. 关于G0、G1、G2、G3的名词解释
  11. 南明区建成呼叫座席11710席
  12. html网页怎么播放无损,无损音质和标准音质有什么区别
  13. matlab用gui 画函数,MATLAB GUI ,2,使用MATLAB的函数来实现MATLAB GUI,part 1,图
  14. python爬虫——Request之get请求和post请求
  15. 读书笔记——《802.11无线网络权威指南》
  16. 苹果7计算机在哪里,iPhone7白苹果怎么办 iPhone7白苹果重启解决方法【详细介绍】...
  17. JS逆向 | 某美食优惠聚合平台
  18. IOS 屏幕适配理论篇
  19. 中国版Meerkat来了,趣播手中有一利器,可大幅拉低直播流量
  20. STM32CubeMX生成STM32F072 USB 自定义HID Device

热门文章

  1. python进程监控 supervisor_使用Python的Supervisor进行进程监控以及自动启动
  2. python 字符转义_2500字 字符串专题总结
  3. treeview控件怎么折叠_拍摄的视频闪烁怎么办?一招就能搞定,电脑手机都适用...
  4. 单调有界定理适用于函数吗_《实变函数》——论有界变差函数
  5. msp430中如何连续对位进行取反_四元数数控:如何保养视觉对位平台?
  6. @excel注解_Excel导入导出Java解决方案推荐
  7. http://www.od85c.com.cn/html/,OllyDbg script for unpacking Enigma 4.xx and 5.xx
  8. yota3墨水屏设置_汉阳环卫工节前给道路隔音屏“洗澡”
  9. 网站如何进行渠道跟踪_网站如何进行搜索引擎优化?
  10. 【LeetCode笔记】64. 最小路径和(Java、动态规划)