org.apache.lucene.index.IndexWriterConfig.OpenMode#CREATE_OR_APPEND源码实例Demo

下面列出了org.apache.lucene.index.IndexWriterConfig.OpenMode#CREATE_OR_APPEND 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: lucene-solr   文件: TestDirectoryTaxonomyWriter.java
@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();
}
 
源代码2 项目: lucene-solr   文件: TestDirectoryTaxonomyWriter.java
@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(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();
}
 
源代码3 项目: lucene-solr   文件: LiveIndexWriterConfig.java
LiveIndexWriterConfig(Analyzer analyzer) {
  this.analyzer = analyzer;
  ramBufferSizeMB = IndexWriterConfig.DEFAULT_RAM_BUFFER_SIZE_MB;
  maxBufferedDocs = IndexWriterConfig.DEFAULT_MAX_BUFFERED_DOCS;
  mergedSegmentWarmer = null;
  delPolicy = new KeepOnlyLastCommitDeletionPolicy();
  commit = null;
  useCompoundFile = IndexWriterConfig.DEFAULT_USE_COMPOUND_FILE_SYSTEM;
  openMode = OpenMode.CREATE_OR_APPEND;
  similarity = IndexSearcher.getDefaultSimilarity();
  mergeScheduler = new ConcurrentMergeScheduler();
  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;
  perThreadHardLimitMB = IndexWriterConfig.DEFAULT_RAM_PER_THREAD_HARD_LIMIT_MB;
  maxCommitMergeWaitMillis = IndexWriterConfig.DEFAULT_MAX_COMMIT_MERGE_WAIT_MILLIS;
}
 
源代码4 项目: lucene-solr   文件: TestDirectoryTaxonomyWriter.java
@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().
  try (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();
  }
}
 
源代码5 项目: lucene-solr   文件: DirectoryTaxonomyWriter.java
/** Create this with {@code OpenMode.CREATE_OR_APPEND}. */
public DirectoryTaxonomyWriter(Directory d) throws IOException {
  this(d, OpenMode.CREATE_OR_APPEND);
}
 
源代码6 项目: lucene-solr   文件: TestDirectoryTaxonomyWriter.java
@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);
  assertTrue(taxoWriter.getCache() == 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.setLiveCommitData(userCommitData.entrySet());
  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.setLiveCommitData(new HashMap<String, String>(){{
    put("just", "data");
  }}.entrySet());
  taxoWriter.commit();
  
  // verify taxoWriter.getCommitData()
  Map<String,String> data = new HashMap<>();
  Iterable<Map.Entry<String,String>> iter = taxoWriter.getLiveCommitData();
  if (iter != null) {
    for(Map.Entry<String,String> ent : iter) {
      data.put(ent.getKey(), ent.getValue());
    }
  }
  
  assertNotNull(DirectoryTaxonomyWriter.INDEX_EPOCH
      + " not found in taoxWriter.commitData", data.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();
}
 
/**
 * {@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);
}
 
源代码8 项目: lucene-solr   文件: SolrSnapshotMetaDataManager.java
/**
 * A constructor.
 *
 * @param dir The directory where the snapshot meta-data should be stored. Enables updating
 *            the existing meta-data.
 * @throws IOException in case of errors.
 */
public SolrSnapshotMetaDataManager(SolrCore solrCore, Directory dir) throws IOException {
  this(solrCore, dir, OpenMode.CREATE_OR_APPEND);
}