第一次创建索引时报错,错误信息如下:
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(); }