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 index
引用
create - true to create the index or overwrite the existing one; false to append to the existing index
true:创建新的索引或者覆盖现有索引
false:追加索引到现有索引。
true:创建新的索引或者覆盖现有索引
false:追加索引到现有索引。
所以。当该参数为false,而所以目录下由不存在索引的时候,便会产生该异常。
引用
java.io.FileNotFoundException: no segments* file found in org.apache.lucene.store.FSDirectory@.....
解决方法:
在new IndexSearcher(path); 前面加一句
IndexWriter writer = new IndexWriter(path, new StandardAnalyzer(), true);