lucene创建索引中的构造函数IndexWriter(String path, Analyzer a, boolean create, IndexWriter.MaxFieldLength mfl) ,这里的boolean create参数的意思并非是否创建索引,而是覆盖还是追加的意思。原文见官方文档:create - true to create the index or overwrite the existing one; false to append to the existing indexcreate - true to create the index or overwrite the existing one; false to append to the existing index
true:创建新的索引或者覆盖现有索引
false:追加索引到现有索引。
所以。当该参数为false,而所以目录下由不存在索引的时候,便会产生该异常。java.io.FileNotFoundException: no segments* file found in org.apache.lucene.store.FSDirectory@D:\lucenedir\index: files:
at org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:604)
at org.apache.lucene.index.SegmentInfos.read(SegmentInfos.java:272)
at org.apache.lucene.index.IndexWriter.init(IndexWriter.java:1072)
at org.apache.lucene.index.IndexWriter.(IndexWriter.java:550)
writer = new IndexWriter(DIR, new StandardAnalyzer(), false);
writer = new IndexWriter(DIR, new StandardAnalyzer(), true);
在索引没有建立前,使用增量索引时,会发生这个异常
在索引建立时使用
writer = new IndexWriter(DIR, new StandardAnalyzer(), true);
以后使用
writer = new IndexWriter(DIR, new StandardAnalyzer(), false);
阅读(5221) | 评论(0) | 转发(0) |