本文整理匯總了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;
}