我正在使用 Lucene 6.6.0,我想使用 Lucene 的近实时搜索功能。但是,我无法实现它。我尝试获取该功能的方式如下:
我初始化一个 IndexReader 实例:
this.reader = DirectoryReader.open(this.directory);
让我们假设已经通过 IndexWriter 实例对索引进行了一些更改。然后,如果我理解正确,我需要第二个 IndexReader 实例来提交更新:
this.newReader = DirectoryReader.openIfChanged(this.reader);
if (this.newReader != null) {
// Update the IndexSearcher with the new IndexReader instance
this.searcher = new IndexSearcher(this.newReader);
this.reader.close();
}
这里的问题是由于以下错误,代码无法编译:The method openIfChanged(DirectoryReader) in the type DirectoryReader is not applicable for the arguments (IndexReader)
.
我应该如何更新IndexReader
呢?
其次,如果我再次更新索引,我将需要另一个 IndexReader 实例,不是吗?在程序执行期间自由更新索引的最佳方法是在每次更新后在 2 个 IndexReader 实例之间切换吗?
谢谢你。