當前位置: 首頁>>代碼示例>>Java>>正文


Java OpenMode.CREATE_OR_APPEND屬性代碼示例

本文整理匯總了Java中org.apache.lucene.index.IndexWriterConfig.OpenMode.CREATE_OR_APPEND屬性的典型用法代碼示例。如果您正苦於以下問題:Java OpenMode.CREATE_OR_APPEND屬性的具體用法?Java OpenMode.CREATE_OR_APPEND怎麽用?Java OpenMode.CREATE_OR_APPEND使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.apache.lucene.index.IndexWriterConfig.OpenMode的用法示例。


在下文中一共展示了OpenMode.CREATE_OR_APPEND屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testCommit

@Test
public void testCommit() throws Exception {
  // Verifies that nothing is committed to the underlying Directory, if
  // commit() wasn't called.
  Directory dir = newDirectory();
  DirectoryTaxonomyWriter ltw = new DirectoryTaxonomyWriter(dir, OpenMode.CREATE_OR_APPEND, NO_OP_CACHE);
  assertFalse(DirectoryReader.indexExists(dir));
  ltw.commit(); // first commit, so that an index will be created
  ltw.addCategory(new FacetLabel("a"));
  
  IndexReader r = DirectoryReader.open(dir);
  assertEquals("No categories should have been committed to the underlying directory", 1, r.numDocs());
  r.close();
  ltw.close();
  dir.close();
}
 
開發者ID:europeana,項目名稱:search,代碼行數:16,代碼來源:TestDirectoryTaxonomyWriter.java

示例2: testBackwardsCompatibility

@Test
public void testBackwardsCompatibility() throws Exception {
  // tests that if the taxonomy index doesn't have the INDEX_EPOCH
  // property (supports pre-3.6 indexes), all still works.
  Directory dir = newDirectory();
  
  // create an empty index first, so that DirTaxoWriter initializes indexEpoch to 1.
  new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, null)).close();
  
  DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(dir, OpenMode.CREATE_OR_APPEND, NO_OP_CACHE);
  taxoWriter.close();
  
  DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(dir);
  assertEquals(1, Integer.parseInt(taxoReader.getCommitUserData().get(DirectoryTaxonomyWriter.INDEX_EPOCH)));
  assertNull(TaxonomyReader.openIfChanged(taxoReader));
  taxoReader.close();
  
  dir.close();
}
 
開發者ID:europeana,項目名稱:search,代碼行數:19,代碼來源:TestDirectoryTaxonomyWriter.java

示例3: LiveIndexWriterConfig

LiveIndexWriterConfig(Analyzer analyzer, Version matchVersion) {
  this.analyzer = analyzer;
  this.matchVersion = matchVersion;
  ramBufferSizeMB = IndexWriterConfig.DEFAULT_RAM_BUFFER_SIZE_MB;
  maxBufferedDocs = IndexWriterConfig.DEFAULT_MAX_BUFFERED_DOCS;
  maxBufferedDeleteTerms = IndexWriterConfig.DEFAULT_MAX_BUFFERED_DELETE_TERMS;
  readerTermsIndexDivisor = IndexWriterConfig.DEFAULT_READER_TERMS_INDEX_DIVISOR;
  mergedSegmentWarmer = null;
  termIndexInterval = IndexWriterConfig.DEFAULT_TERM_INDEX_INTERVAL; // TODO: this should be private to the codec, not settable here
  delPolicy = new KeepOnlyLastCommitDeletionPolicy();
  commit = null;
  useCompoundFile = IndexWriterConfig.DEFAULT_USE_COMPOUND_FILE_SYSTEM;
  openMode = OpenMode.CREATE_OR_APPEND;
  similarity = IndexSearcher.getDefaultSimilarity();
  mergeScheduler = new ConcurrentMergeScheduler();
  writeLockTimeout = IndexWriterConfig.WRITE_LOCK_TIMEOUT;
  indexingChain = DocumentsWriterPerThread.defaultIndexingChain;
  codec = Codec.getDefault();
  if (codec == null) {
    throw new NullPointerException();
  }
  infoStream = InfoStream.getDefault();
  mergePolicy = new TieredMergePolicy();
  flushPolicy = new FlushByRamOrCountsPolicy();
  readerPooling = IndexWriterConfig.DEFAULT_READER_POOLING;
  indexerThreadPool = new DocumentsWriterPerThreadPool(IndexWriterConfig.DEFAULT_MAX_THREAD_STATES);
  perThreadHardLimitMB = IndexWriterConfig.DEFAULT_RAM_PER_THREAD_HARD_LIMIT_MB;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:28,代碼來源:LiveIndexWriterConfig.java

示例4: testRecreateAndRefresh

@Test
public void testRecreateAndRefresh() throws Exception {
  // DirTaxoWriter lost the INDEX_EPOCH property if it was opened in
  // CREATE_OR_APPEND (or commit(userData) called twice), which could lead to
  // DirTaxoReader succeeding to refresh().
  Directory dir = newDirectory();
  
  DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(dir, OpenMode.CREATE_OR_APPEND, NO_OP_CACHE);
  touchTaxo(taxoWriter, new FacetLabel("a"));
  
  TaxonomyReader taxoReader = new DirectoryTaxonomyReader(dir);

  touchTaxo(taxoWriter, new FacetLabel("b"));
  
  TaxonomyReader newtr = TaxonomyReader.openIfChanged(taxoReader);
  taxoReader.close();
  taxoReader = newtr;
  assertEquals(1, Integer.parseInt(taxoReader.getCommitUserData().get(DirectoryTaxonomyWriter.INDEX_EPOCH)));

  // now recreate the taxonomy, and check that the epoch is preserved after opening DirTW again.
  taxoWriter.close();
  taxoWriter = new DirectoryTaxonomyWriter(dir, OpenMode.CREATE, NO_OP_CACHE);
  touchTaxo(taxoWriter, new FacetLabel("c"));
  taxoWriter.close();
  
  taxoWriter = new DirectoryTaxonomyWriter(dir, OpenMode.CREATE_OR_APPEND, NO_OP_CACHE);
  touchTaxo(taxoWriter, new FacetLabel("d"));
  taxoWriter.close();

  newtr = TaxonomyReader.openIfChanged(taxoReader);
  taxoReader.close();
  taxoReader = newtr;
  assertEquals(2, Integer.parseInt(taxoReader.getCommitUserData().get(DirectoryTaxonomyWriter.INDEX_EPOCH)));

  taxoReader.close();
  dir.close();
}
 
開發者ID:europeana,項目名稱:search,代碼行數:37,代碼來源:TestDirectoryTaxonomyWriter.java

示例5: DirectoryTaxonomyWriter

/** Create this with {@code OpenMode.CREATE_OR_APPEND}. */
public DirectoryTaxonomyWriter(Directory d) throws IOException {
  this(d, OpenMode.CREATE_OR_APPEND);
}
 
開發者ID:europeana,項目名稱:search,代碼行數:4,代碼來源:DirectoryTaxonomyWriter.java

示例6: testCommitUserData

@Test
public void testCommitUserData() throws Exception {
  // Verifies taxonomy commit data
  Directory dir = newDirectory();
  DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(dir, OpenMode.CREATE_OR_APPEND, NO_OP_CACHE);
  taxoWriter.addCategory(new FacetLabel("a"));
  taxoWriter.addCategory(new FacetLabel("b"));
  Map<String, String> userCommitData = new HashMap<>();
  userCommitData.put("testing", "1 2 3");
  taxoWriter.setCommitData(userCommitData);
  taxoWriter.close();
  DirectoryReader r = DirectoryReader.open(dir);
  assertEquals("2 categories plus root should have been committed to the underlying directory", 3, r.numDocs());
  Map <String, String> readUserCommitData = r.getIndexCommit().getUserData();
  assertTrue("wrong value extracted from commit data", 
      "1 2 3".equals(readUserCommitData.get("testing")));
  assertNotNull(DirectoryTaxonomyWriter.INDEX_EPOCH + " not found in commitData", readUserCommitData.get(DirectoryTaxonomyWriter.INDEX_EPOCH));
  r.close();
  
  // open DirTaxoWriter again and commit, INDEX_EPOCH should still exist
  // in the commit data, otherwise DirTaxoReader.refresh() might not detect
  // that the taxonomy index has been recreated.
  taxoWriter = new DirectoryTaxonomyWriter(dir, OpenMode.CREATE_OR_APPEND, NO_OP_CACHE);
  taxoWriter.addCategory(new FacetLabel("c")); // add a category so that commit will happen
  taxoWriter.setCommitData(new HashMap<String, String>(){{
    put("just", "data");
  }});
  taxoWriter.commit();
  
  // verify taxoWriter.getCommitData()
  assertNotNull(DirectoryTaxonomyWriter.INDEX_EPOCH
      + " not found in taoxWriter.commitData", taxoWriter.getCommitData().get(DirectoryTaxonomyWriter.INDEX_EPOCH));
  taxoWriter.close();
  
  r = DirectoryReader.open(dir);
  readUserCommitData = r.getIndexCommit().getUserData();
  assertNotNull(DirectoryTaxonomyWriter.INDEX_EPOCH + " not found in commitData", readUserCommitData.get(DirectoryTaxonomyWriter.INDEX_EPOCH));
  r.close();
  
  dir.close();
}
 
開發者ID:europeana,項目名稱:search,代碼行數:41,代碼來源:TestDirectoryTaxonomyWriter.java

示例7: PersistentSnapshotDeletionPolicy

/**
 * {@link PersistentSnapshotDeletionPolicy} wraps another
 * {@link IndexDeletionPolicy} to enable flexible
 * snapshotting, passing {@link OpenMode#CREATE_OR_APPEND}
 * by default.
 * 
 * @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.
 */
public PersistentSnapshotDeletionPolicy(IndexDeletionPolicy primary,
    Directory dir) throws IOException {
  this(primary, dir, OpenMode.CREATE_OR_APPEND);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:PersistentSnapshotDeletionPolicy.java


注:本文中的org.apache.lucene.index.IndexWriterConfig.OpenMode.CREATE_OR_APPEND屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。