`

lucene:no segments* file found in org.apache.lucene.store.FSDirectory@异常

 
阅读更多
  1. 目的:我想把内存中的索引合并到磁盘文件中。
  2. 异常:org.apache.lucene.index.IndexNotFoundException: no segments* file found in org.apache.lucene.store.RAMDirectory@1e94b0ca lockFactory=org.apache.lucene.store.SingleInstanceLockFactory@33e2ad75: files: [_0.fdx, _0.fdt]
     at org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:741)
     at org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:630)
     at org.apache.lucene.index.SegmentInfos.read(SegmentInfos.java:343)
     at org.apache.lucene.index.IndexWriter.addIndexes(IndexWriter.java:2333)
     at org.apache.lucene.demo.IKAnalyzerT.createIndex(IKAnalyzerT.java:45)
     at org.apache.lucene.demo.IKAnalyzerT.main(IKAnalyzerT.java:58)

意思是:我在把内存索引合并到磁盘的时候 内存中没有索引文件。

我的解决方案参考: 在索引库没有建立并且没有索引文件的时候首先要commit一下让他建立一个

  

  1. public class X {  
  2.     public static void main(String[] args) throws Exception{  
  3.         Analyzer a = new StandardAnalyzer(Version.LUCENE_CURRENT);  
  4.         IndexDeletionPolicy commitDeletionPolicy = new  SolrDeletionPolicy();  
  5.         FSDirectory directory = FSDirectory.open(new File("c:\\"));  
  6.           
  7.         IndexWriterConfig config = new   
  8.         IndexWriterConfig(Version.LUCENE_CURRENT,a);   
  9.         config.setOpenMode(OpenMode.CREATE_OR_APPEND);   
  10.         config.setIndexDeletionPolicy(commitDeletionPolicy);   
  11.         IndexWriter writer = new IndexWriter(directory, config);   
  12.   
  13.         // -----------------   
  14.         // 在索引库没有建立并且没有索引文件的时候首先要commit一下让他建立一个  
  15.         // 索引库的版本信息  
  16.         //writer.commit();   
  17.         // -----------------   
  18.           
  19.         //如果第一次没有commit就打开一个索引读取器的话就会报异常  
  20.         IndexReader reader = IndexReader.open(directory);   
  21.         System.out.println(reader);  
  22.         //Exception in thread "main" org.apache.lucene.index.IndexNotFoundException: no segments* file found in org.apache.lucene.store.SimpleFSDirectory@C:\ lockFactory=org.apache.lucene.store.NativeFSLockFactory@15a8767: files: [bootmgr, BOOTSECT.BAK, pagefile.sys, write.lock]  
  23.         // at  
  24.         // org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:711)  
  25.         // at  
  26.         // org.apache.lucene.index.DirectoryReader.open(DirectoryReader.java:75)  
  27.         // at org.apache.lucene.index.IndexReader.open(IndexReader.java:428)  
  28.         // at org.apache.lucene.index.IndexReader.open(IndexReader.java:274)  
  29.         // at com.zyb.solrQuery.X.main(X.java:39)  
  30.     }  
  31. }  

 

分享到:
评论

相关推荐

    lucene-core-7.7.0-API文档-中文版.zip

    Maven坐标:org.apache.lucene:lucene-core:7.7.0; 标签:apache、lucene、core、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档...

    lucene org.apache

    org.apache.lucene.analysis.cjk.CJKAnalyzer .......

    Lucene使用

    Exception in thread "main" java.lang.AbstractMethodError: org.apache.lucene.analysis.TokenStream.incrementToken()Z 换用svn里源码版正常 http://paoding.googlecode.com/svn/trunk/paoding-analysis/

    Lucene开发详解.pdf

    6. **org.apache.lucene.store**:该包负责与存储系统的交互,进行数据读写操作。 7. **org.apache.lucene.util**:该包包含了一些公共工具类,为其他包提供辅助功能。 #### 三、中文支持与分析器 Lucene默认提供...

    apache Lucene4.7最全最新的jar包

    Apache Lucene是一个高性能、全文本搜索库,由Java编写,被广泛用于开发搜索引擎和需要文本检索功能的应用程序。Apache Lucene 4.7是该库的一个版本,它提供了丰富的功能和改进,使得开发者能够轻松地在他们的应用中...

    与lucene3.0兼容的庖丁jar包

    Exception in thread "main" java.lang.AbstractMethodError: org.apache.lucene.analysis.TokenStream.incrementToken()Z at org.apache.lucene.index.DocInverterPerField.processFields(DocInverterPerField....

    lucene基础学习笔记&源码

    6. **异常处理和日志记录**:分析错误处理机制,以及如何利用 `org.apache.lucene.util` 中的工具类进行日志记录。 通过阅读源码,我们可以深入了解 Lucene 的内部机制,这对于定制和优化 Lucene 应用,以及解决...

    lucene核心资源包以及lucene的api

    - **Analyzer API**: 如`org.apache.lucene.analysis.Analyzer`,提供了创建自定义分析器的方法,如`createComponents(String fieldName, Reader reader)`,用于创建TokenStream。 - **IndexWriter API**: 如`org....

    Annotated Lucene 中文版 Lucene源码剖析

    - `org.apache.lucene.store.Directory`接口定义了存储索引的基本行为,其实现类包括基于文件系统的`FSDirectory`和基于内存的`RAMDirectory`。 - `org.apache.lucene.store.IndexInput`和`org.apache.lucene....

    Lucene搜索技术

    - **org.apache.lucene.document**:定义了Document对象,作为存储结构,文档由多个Field组成,每个Field对应不同类型的文献数据。 - **org.apache.lucene.field**:表示文档中的各个字段,定义了字段的类型和属性。...

    lucene 全文检索

    5. **org.apache.lucene.store**: 这个包包含了存储索引的接口和实现,如内存存储`RAMDirectory`和文件系统存储`FSDirectory`。 6. **org.apache.lucene.queryparser**: 提供了查询解析器,将用户输入的字符串转换...

    Hadoop源码的入门解析

    Hadoop是一个开源的分布式计算框架,源于Apache Lucene项目,主要负责大规模数据的分布式存储和处理。它由几个核心组件构成,包括Hadoop Distributed File System (HDFS)和MapReduce计算模型。 **HDFS**是Hadoop的...

    lucene-spatial-6.6.0-API文档-中英对照版.zip

    Maven坐标:org.apache.lucene:lucene-spatial:6.6.0; 标签:apache、lucene、spatial、jar包、java、API文档、中英对照版; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 ...

    lucene 入门整理

    7. **`org.apache.lucene.store`**:处理索引数据的存储与检索,封装了底层的I/O操作,确保数据的安全与高效访问。 8. **`org.apache.lucene.util`**:提供一系列工具类和常量,辅助Lucene的其他组件完成特定任务。...

    Lucene建立索引及查询包含“java”关键字 示例代码

    import org.apache.lucene.store.FSDirectory; import java.nio.file.Paths; public class IndexingExample { public static void main(String[] args) throws Exception { Directory directory = FSDirectory....

    struts2 + spring + lucene_search 实例

    import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.queryParser.QueryParser; import org.apache.lucene.search.Hits; import ...

    基于JAVA的搜索引擎 lucene-2.2.0

    Exception in thread "main" java.io.FileNotFoundException: no segments* file found in org.apache.lucene.store.FSDirectory@E:\index: files: at org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run...

    Linux源码剖析

    - **`org.apache.lucene.store.FSDirectory`**:使用本地文件系统作为存储后端。 - **`org.apache.lucene.store.RAMDirectory`**:将索引存储在内存中,适用于测试环境或小型应用。 - **`org.apache.lucene.store....

    Lucene:基于Java的全文检索引擎简介.rar

    Lucene是一个高度可扩展的、高性能的全文检索库,由Apache软件基金会开发并维护。它是Java开发者在构建搜索引擎应用时的首选工具,因为它提供了完整的索引和搜索功能,同时也支持复杂的查询语法。Lucene的主要目标是...

Global site tag (gtag.js) - Google Analytics