本文整理汇总了Java中org.apache.lucene.index.DirectoryReader.openIfChanged方法的典型用法代码示例。如果您正苦于以下问题:Java DirectoryReader.openIfChanged方法的具体用法?Java DirectoryReader.openIfChanged怎么用?Java DirectoryReader.openIfChanged使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.index.DirectoryReader
的用法示例。
在下文中一共展示了DirectoryReader.openIfChanged方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: refreshReader
import org.apache.lucene.index.DirectoryReader; //导入方法依赖的package包/类
private DirectoryReader refreshReader(DirectoryReader reader) throws IOException {
DirectoryReader oldReader = reader;
reader = DirectoryReader.openIfChanged(reader);
if (reader != oldReader) {
oldReader.close();
}
return reader;
}
示例2: testCoreCacheKey
import org.apache.lucene.index.DirectoryReader; //导入方法依赖的package包/类
/** Test that core cache key (needed for NRT) is working */
public void testCoreCacheKey() throws Exception {
Directory dir = newDirectory();
IndexWriterConfig iwc = new IndexWriterConfig(null);
iwc.setMaxBufferedDocs(100);
iwc.setMergePolicy(NoMergePolicy.INSTANCE);
IndexWriter iw = new IndexWriter(dir, iwc);
// add two docs, id:0 and id:1
Document doc = new Document();
Field idField = new StringField("id", "", Field.Store.NO);
doc.add(idField);
idField.setStringValue("0");
iw.addDocument(doc);
idField.setStringValue("1");
iw.addDocument(doc);
// open reader
ShardId shardId = new ShardId("fake", "_na_", 1);
DirectoryReader ir = ElasticsearchDirectoryReader.wrap(DirectoryReader.open(iw), shardId);
assertEquals(2, ir.numDocs());
assertEquals(1, ir.leaves().size());
// delete id:0 and reopen
iw.deleteDocuments(new Term("id", "0"));
DirectoryReader ir2 = DirectoryReader.openIfChanged(ir);
// we should have the same cache key as before
assertEquals(1, ir2.numDocs());
assertEquals(1, ir2.leaves().size());
assertSame(ir.leaves().get(0).reader().getCoreCacheKey(), ir2.leaves().get(0).reader().getCoreCacheKey());
IOUtils.close(ir, ir2, iw, dir);
}
示例3: reopen
import org.apache.lucene.index.DirectoryReader; //导入方法依赖的package包/类
public static DirectoryReader reopen(DirectoryReader reader, boolean newReaderExpected) throws IOException {
DirectoryReader newReader = DirectoryReader.openIfChanged(reader);
if (newReader != null) {
reader.close();
} else {
assertFalse(newReaderExpected);
}
return newReader;
}