第一次创建索引时报错,错误信息如下:
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]
原因:
在索引库没有建立时,需要先执行commit创立。
解决办法:
在第一次创建索引前添加一行indexWrite.commit()。
try {
directory = FSDirectory.open(new File("D://index/test"));
if (indexWrite.isLocked(directory)) {
indexWrite.unlock(directory);
}
indexWrite = new IndexWriter(directory,indexWriteConfig);
//indexWrite.commit();第一次运行时执行
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
本文介绍了一种在使用Lucene创建索引过程中遇到的IndexNotFoundException,并提供了详细的错误信息及可能的原因分析。针对该问题,文章给出了具体的解决办法,即在创建索引之前先执行commit操作。
1339

被折叠的 条评论
为什么被折叠?



