当前位置: 首页>>代码示例>>Java>>正文


Java OpenMode.APPEND属性代码示例

本文整理汇总了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");
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:32,代码来源:PersistentSnapshotDeletionPolicy.java

示例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();
}
 
开发者ID:europeana,项目名称:search,代码行数:12,代码来源:TestPersistentSnapshotDeletionPolicy.java

示例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();
}
 
开发者ID:europeana,项目名称:search,代码行数:15,代码来源:TestPersistentSnapshotDeletionPolicy.java

示例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();
}
 
开发者ID:europeana,项目名称:search,代码行数:15,代码来源:TestPersistentSnapshotDeletionPolicy.java

示例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();
}
 
开发者ID:europeana,项目名称:search,代码行数:46,代码来源:TestPersistentSnapshotDeletionPolicy.java


注:本文中的org.apache.lucene.index.IndexWriterConfig.OpenMode.APPEND属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。