lucene:no segments* file found in org.apache.lucene.store.FSDirectory@异常
- 目的:我想把内存中的索引合并到磁盘文件中。
- 异常: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一下让他建立一个
- public class X {
- public static void main(String[] args) throws Exception{
- Analyzer a = new StandardAnalyzer(Version.LUCENE_CURRENT);
- IndexDeletionPolicy commitDeletionPolicy = new SolrDeletionPolicy();
- FSDirectory directory = FSDirectory.open(new File("c:\\"));
- IndexWriterConfig config = new
- IndexWriterConfig(Version.LUCENE_CURRENT,a);
- config.setOpenMode(OpenMode.CREATE_OR_APPEND);
- config.setIndexDeletionPolicy(commitDeletionPolicy);
- IndexWriter writer = new IndexWriter(directory, config);
- // -----------------
- // 在索引库没有建立并且没有索引文件的时候首先要commit一下让他建立一个
- // 索引库的版本信息
- //writer.commit();
- // -----------------
- //如果第一次没有commit就打开一个索引读取器的话就会报异常
- IndexReader reader = IndexReader.open(directory);
- System.out.println(reader);
- //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]
- // at
- // org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:711)
- // at
- // org.apache.lucene.index.DirectoryReader.open(DirectoryReader.java:75)
- // at org.apache.lucene.index.IndexReader.open(IndexReader.java:428)
- // at org.apache.lucene.index.IndexReader.open(IndexReader.java:274)
- // at com.zyb.solrQuery.X.main(X.java:39)
- }
- }
相关推荐
Jacry 2020-07-04
Kafka 2020-09-18
Wepe0 2020-10-30
杜倩 2020-10-29
windle 2020-10-29
minerd 2020-10-28
mengzuchao 2020-10-22
Junzizhiai 2020-10-10
bxqybxqy 2020-09-30
风之沙城 2020-09-24
kingszelda 2020-09-22
大唐帝国前营 2020-08-18
yixu0 2020-08-17
TangCuYu 2020-08-15
xiaoboliu00 2020-08-15
songshijiazuaa 2020-08-15
xclxcl 2020-08-03
zmzmmf 2020-08-03
newfarhui 2020-08-03