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