org.apache.lucene.index.IndexNotFoundException: no segments* file found in org.apache.lucene.store.SimpleFSDirectory@D:\lucene\index01 lockFactory=org.apache.lucene.store.NativeFSLockFactory@26e431: files: [write.lock, _0.fdt, _0.fdx]
at org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:712)
at org.apache.lucene.index.DirectoryReader.open(DirectoryReader.java:75)
at org.apache.lucene.index.IndexReader.open(IndexReader.java:462)
at org.apache.lucene.index.IndexReader.open(IndexReader.java:308)
at com.lyl.test.HelloLucene.sercher(HelloLucene.java:73)
at com.lyl.test.TestLucene.search1(TestLucene.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
单元测试过程中,创建索引读取器IndexReader的时候,抛出异常,并发现索引文件都为0kb,最终确认是索引IndexWriter写入器没有将缓存中的信息输入文件内,
解决方法是:写入器添加好文件索引后,关闭写入器,就ok了!