本文整理汇总了Java中org.apache.lucene.index.IndexWriterConfig.OpenMode.APPEND属性的典型用法代码示例。如果您正苦于以下问题:Java OpenMode.APPEND属性的具体用法?Java OpenMode.APPEND怎么用?Java OpenMode.APPEND使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.lucene.index.IndexWriterConfig.OpenMode
的用法示例。
在下文中一共展示了OpenMode.APPEND属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PersistentSnapshotDeletionPolicy
/**
* {@link PersistentSnapshotDeletionPolicy} wraps another
* {@link IndexDeletionPolicy} to enable flexible snapshotting.
*
* @param primary
* the {@link IndexDeletionPolicy} that is used on non-snapshotted
* commits. Snapshotted commits, by definition, are not deleted until
* explicitly released via {@link #release}.
* @param dir
* the {@link Directory} which will be used to persist the snapshots
* information.
* @param mode
* specifies whether a new index should be created, deleting all
* existing snapshots information (immediately), or open an existing
* index, initializing the class with the snapshots information.
*/
public PersistentSnapshotDeletionPolicy(IndexDeletionPolicy primary,
Directory dir, OpenMode mode) throws IOException {
super(primary);
this.dir = dir;
if (mode == OpenMode.CREATE) {
clearPriorSnapshots();
}
loadPriorSnapshots();
if (mode == OpenMode.APPEND && nextWriteGen == 0) {
throw new IllegalStateException("no snapshots stored in this directory");
}
}
示例2: testMissingSnapshots
@Test
public void testMissingSnapshots() throws Exception {
Directory dir = newDirectory();
try {
new PersistentSnapshotDeletionPolicy(
new KeepOnlyLastCommitDeletionPolicy(), dir, OpenMode.APPEND);
fail("did not hit expected exception");
} catch (IllegalStateException ise) {
// expected
}
dir.close();
}
示例3: testSnapshotRelease
@Test
public void testSnapshotRelease() throws Exception {
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, getConfig(random(), getDeletionPolicy(dir)));
PersistentSnapshotDeletionPolicy psdp = (PersistentSnapshotDeletionPolicy) writer.getConfig().getIndexDeletionPolicy();
prepareIndexAndSnapshots(psdp, writer, 1);
writer.close();
psdp.release(snapshots.get(0));
psdp = new PersistentSnapshotDeletionPolicy(
new KeepOnlyLastCommitDeletionPolicy(), dir, OpenMode.APPEND);
assertEquals("Should have no snapshots !", 0, psdp.getSnapshotCount());
dir.close();
}
示例4: testSnapshotReleaseByGeneration
@Test
public void testSnapshotReleaseByGeneration() throws Exception {
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, getConfig(random(), getDeletionPolicy(dir)));
PersistentSnapshotDeletionPolicy psdp = (PersistentSnapshotDeletionPolicy) writer.getConfig().getIndexDeletionPolicy();
prepareIndexAndSnapshots(psdp, writer, 1);
writer.close();
psdp.release(snapshots.get(0).getGeneration());
psdp = new PersistentSnapshotDeletionPolicy(
new KeepOnlyLastCommitDeletionPolicy(), dir, OpenMode.APPEND);
assertEquals("Should have no snapshots !", 0, psdp.getSnapshotCount());
dir.close();
}
示例5: testExistingSnapshots
@Test
public void testExistingSnapshots() throws Exception {
int numSnapshots = 3;
MockDirectoryWrapper dir = newMockDirectory();
dir.setEnableVirusScanner(false); // test relies on files actually being deleted
IndexWriter writer = new IndexWriter(dir, getConfig(random(), getDeletionPolicy(dir)));
PersistentSnapshotDeletionPolicy psdp = (PersistentSnapshotDeletionPolicy) writer.getConfig().getIndexDeletionPolicy();
assertNull(psdp.getLastSaveFile());
prepareIndexAndSnapshots(psdp, writer, numSnapshots);
assertNotNull(psdp.getLastSaveFile());
writer.close();
// Make sure only 1 save file exists:
int count = 0;
for(String file : dir.listAll()) {
if (file.startsWith(PersistentSnapshotDeletionPolicy.SNAPSHOTS_PREFIX)) {
count++;
}
}
assertEquals(1, count);
// Make sure we fsync:
dir.crash();
dir.clearCrash();
// Re-initialize and verify snapshots were persisted
psdp = new PersistentSnapshotDeletionPolicy(
new KeepOnlyLastCommitDeletionPolicy(), dir, OpenMode.APPEND);
writer = new IndexWriter(dir, getConfig(random(), psdp));
psdp = (PersistentSnapshotDeletionPolicy) writer.getConfig().getIndexDeletionPolicy();
assertEquals(numSnapshots, psdp.getSnapshots().size());
assertEquals(numSnapshots, psdp.getSnapshotCount());
assertSnapshotExists(dir, psdp, numSnapshots, false);
writer.addDocument(new Document());
writer.commit();
snapshots.add(psdp.snapshot());
assertEquals(numSnapshots+1, psdp.getSnapshots().size());
assertEquals(numSnapshots+1, psdp.getSnapshotCount());
assertSnapshotExists(dir, psdp, numSnapshots+1, false);
writer.close();
dir.close();
}