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


Java IndexWriterConfig.setIndexDeletionPolicy方法代码示例

本文整理汇总了Java中org.apache.lucene.index.IndexWriterConfig.setIndexDeletionPolicy方法的典型用法代码示例。如果您正苦于以下问题:Java IndexWriterConfig.setIndexDeletionPolicy方法的具体用法?Java IndexWriterConfig.setIndexDeletionPolicy怎么用?Java IndexWriterConfig.setIndexDeletionPolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.index.IndexWriterConfig的用法示例。


在下文中一共展示了IndexWriterConfig.setIndexDeletionPolicy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getIndexWriterConfig

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的package包/类
private IndexWriterConfig getIndexWriterConfig(boolean create) {
    final IndexWriterConfig iwc = new IndexWriterConfig(engineConfig.getAnalyzer());
    iwc.setCommitOnClose(false); // we by default don't commit on close
    iwc.setOpenMode(create ? IndexWriterConfig.OpenMode.CREATE : IndexWriterConfig.OpenMode.APPEND);
    iwc.setIndexDeletionPolicy(deletionPolicy);
    // with tests.verbose, lucene sets this up: plumb to align with filesystem stream
    boolean verbose = false;
    try {
        verbose = Boolean.parseBoolean(System.getProperty("tests.verbose"));
    } catch (Exception ignore) {
    }
    iwc.setInfoStream(verbose ? InfoStream.getDefault() : new LoggerInfoStream(logger));
    iwc.setMergeScheduler(mergeScheduler);
    MergePolicy mergePolicy = config().getMergePolicy();
    // Give us the opportunity to upgrade old segments while performing
    // background merges
    mergePolicy = new ElasticsearchMergePolicy(mergePolicy);
    iwc.setMergePolicy(mergePolicy);
    iwc.setSimilarity(engineConfig.getSimilarity());
    iwc.setRAMBufferSizeMB(engineConfig.getIndexingBufferSize().getMbFrac());
    iwc.setCodec(engineConfig.getCodec());
    iwc.setUseCompoundFile(true); // always use compound on flush - reduces # of file-handles on refresh
    return iwc;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:InternalEngine.java

示例2: testNoCommit

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的package包/类
@Test
public void testNoCommit() throws Exception {
  Directory indexDir = newDirectory();
  IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, null);
  conf.setIndexDeletionPolicy(new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy()));
  IndexWriter indexWriter = new IndexWriter(indexDir, conf);
  
  Directory taxoDir = newDirectory();
  SnapshotDirectoryTaxonomyWriter taxoWriter = new SnapshotDirectoryTaxonomyWriter(taxoDir);
  try {
    assertNotNull(new IndexAndTaxonomyRevision(indexWriter, taxoWriter));
    fail("should have failed when there are no commits to snapshot");
  } catch (IllegalStateException e) {
    // expected
  } finally {
    IOUtils.close(indexWriter, taxoWriter, taxoDir, indexDir);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:IndexAndTaxonomyRevisionTest.java

示例3: testSegmentsFileLast

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的package包/类
@Test
public void testSegmentsFileLast() throws Exception {
  Directory indexDir = newDirectory();
  IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, null);
  conf.setIndexDeletionPolicy(new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy()));
  IndexWriter indexWriter = new IndexWriter(indexDir, conf);
  
  Directory taxoDir = newDirectory();
  SnapshotDirectoryTaxonomyWriter taxoWriter = new SnapshotDirectoryTaxonomyWriter(taxoDir);
  try {
    indexWriter.addDocument(newDocument(taxoWriter));
    indexWriter.commit();
    taxoWriter.commit();
    Revision rev = new IndexAndTaxonomyRevision(indexWriter, taxoWriter);
    Map<String,List<RevisionFile>> sourceFiles = rev.getSourceFiles();
    assertEquals(2, sourceFiles.size());
    for (List<RevisionFile> files : sourceFiles.values()) {
      String lastFile = files.get(files.size() - 1).fileName;
      assertTrue(lastFile.startsWith(IndexFileNames.SEGMENTS) && !lastFile.equals(IndexFileNames.SEGMENTS_GEN));
    }
  } finally {
    IOUtils.close(indexWriter, taxoWriter, taxoDir, indexDir);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:IndexAndTaxonomyRevisionTest.java

示例4: setUp

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
  super.setUp();
  publishDir = newMockDirectory();
  handlerDir = newMockDirectory();
  sourceDirFactory = new PerSessionDirectoryFactory(createTempDir("replicationClientTest"));
  replicator = new LocalReplicator();
  callback = new IndexReadyCallback(handlerDir);
  handler = new IndexReplicationHandler(handlerDir, callback);
  client = new ReplicationClient(replicator, handler, sourceDirFactory);
  
  IndexWriterConfig conf = newIndexWriterConfig(null);
  conf.setIndexDeletionPolicy(new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy()));
  publishWriter = new IndexWriter(publishDir, conf);
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:IndexReplicationClientTest.java

示例5: testSegmentsFileLast

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的package包/类
@Test
public void testSegmentsFileLast() throws Exception {
  Directory dir = newDirectory();
  IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, null);
  conf.setIndexDeletionPolicy(new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy()));
  IndexWriter writer = new IndexWriter(dir, conf);
  try {
    writer.addDocument(new Document());
    writer.commit();
    Revision rev = new IndexRevision(writer);
    @SuppressWarnings("unchecked")
    Map<String, List<RevisionFile>> sourceFiles = rev.getSourceFiles();
    assertEquals(1, sourceFiles.size());
    List<RevisionFile> files = sourceFiles.values().iterator().next();
    String lastFile = files.get(files.size() - 1).fileName;
    assertTrue(lastFile.startsWith(IndexFileNames.SEGMENTS) && !lastFile.equals(IndexFileNames.SEGMENTS_GEN));
  } finally {
    IOUtils.close(writer, dir);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:IndexRevisionTest.java

示例6: setUp

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的package包/类
@Before
@Override
public void setUp() throws Exception {
  super.setUp();
  if (VERBOSE) {
    System.setProperty("org.eclipse.jetty.LEVEL", "DEBUG"); // sets stderr logging to DEBUG level
  }
  clientWorkDir = createTempDir("httpReplicatorTest");
  handlerIndexDir = newDirectory();
  serverIndexDir = newDirectory();
  serverReplicator = new LocalReplicator();
  startServer();
  
  IndexWriterConfig conf = newIndexWriterConfig(null);
  conf.setIndexDeletionPolicy(new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy()));
  writer = new IndexWriter(serverIndexDir, conf);
  reader = DirectoryReader.open(writer, false);
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:HttpReplicatorTest.java

示例7: testSerialization

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的package包/类
@Test
public void testSerialization() throws IOException {
  Directory dir = newDirectory();
  IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, null);
  conf.setIndexDeletionPolicy(new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy()));
  IndexWriter writer = new IndexWriter(dir, conf);
  writer.addDocument(new Document());
  writer.commit();
  Revision rev = new IndexRevision(writer);
  
  SessionToken session1 = new SessionToken("17", rev);
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  session1.serialize(new DataOutputStream(baos));
  byte[] b = baos.toByteArray();
  SessionToken session2 = new SessionToken(new DataInputStream(new ByteArrayInputStream(b)));
  assertEquals(session1.id, session2.id);
  assertEquals(session1.version, session2.version);
  assertEquals(1, session2.sourceFiles.size());
  assertEquals(session1.sourceFiles.size(), session2.sourceFiles.size());
  assertEquals(session1.sourceFiles.keySet(), session2.sourceFiles.keySet());
  List<RevisionFile> files1 = session1.sourceFiles.values().iterator().next();
  List<RevisionFile> files2 = session2.sourceFiles.values().iterator().next();
  assertEquals(files1, files2);
  
  IOUtils.close(writer, dir);
}
 
开发者ID:europeana,项目名称:search,代码行数:27,代码来源:SessionTokenTest.java

示例8: setUp

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
  super.setUp();
  publishIndexDir = newDirectory();
  publishTaxoDir = newDirectory();
  handlerIndexDir = newMockDirectory();
  handlerTaxoDir = newMockDirectory();
  clientWorkDir = createTempDir("replicationClientTest");
  sourceDirFactory = new PerSessionDirectoryFactory(clientWorkDir);
  replicator = new LocalReplicator();
  callback = new IndexAndTaxonomyReadyCallback(handlerIndexDir, handlerTaxoDir);
  handler = new IndexAndTaxonomyReplicationHandler(handlerIndexDir, handlerTaxoDir, callback);
  client = new ReplicationClient(replicator, handler, sourceDirFactory);
  
  IndexWriterConfig conf = newIndexWriterConfig(null);
  conf.setIndexDeletionPolicy(new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy()));
  publishIndexWriter = new IndexWriter(publishIndexDir, conf);
  publishTaxoWriter = new SnapshotDirectoryTaxonomyWriter(publishTaxoDir);
  config = new FacetsConfig();
  config.setHierarchical("A", true);
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:IndexAndTaxonomyReplicationClientTest.java

示例9: standardConfig

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的package包/类
private static IndexWriterConfig standardConfig()
{
    IndexWriterConfig writerConfig = new IndexWriterConfig( LuceneDataSource.KEYWORD_ANALYZER );

    writerConfig.setMaxBufferedDocs( 100000 ); // TODO figure out depending on environment?
    writerConfig.setIndexDeletionPolicy( new MultipleBackupDeletionPolicy() );
    writerConfig.setUseCompoundFile( true );

    // TODO: TieredMergePolicy & possibly SortingMergePolicy
    LogByteSizeMergePolicy mergePolicy = new LogByteSizeMergePolicy();
    mergePolicy.setNoCFSRatio( 1.0 );
    mergePolicy.setMinMergeMB( 0.1 );
    mergePolicy.setMergeFactor( 2 );
    writerConfig.setMergePolicy( mergePolicy );

    return writerConfig;
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-lucene5-index,代码行数:18,代码来源:IndexWriterFactories.java

示例10: testUserDataRead

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的package包/类
public void testUserDataRead() throws IOException {
    final ShardId shardId = new ShardId("index", "_na_", 1);
    DirectoryService directoryService = new LuceneManagedDirectoryService(random());
    Store store = new Store(shardId, INDEX_SETTINGS, directoryService, new DummyShardLock(shardId));
    IndexWriterConfig config = newIndexWriterConfig(random(), new MockAnalyzer(random())).setCodec(TestUtil.getDefaultCodec());
    SnapshotDeletionPolicy deletionPolicy = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
    config.setIndexDeletionPolicy(deletionPolicy);
    IndexWriter writer = new IndexWriter(store.directory(), config);
    Document doc = new Document();
    doc.add(new TextField("id", "1", Field.Store.NO));
    writer.addDocument(doc);
    Map<String, String> commitData = new HashMap<>(2);
    String syncId = "a sync id";
    String translogId = "a translog id";
    commitData.put(Engine.SYNC_COMMIT_ID, syncId);
    commitData.put(Translog.TRANSLOG_GENERATION_KEY, translogId);
    writer.setCommitData(commitData);
    writer.commit();
    writer.close();
    Store.MetadataSnapshot metadata;
    metadata = store.getMetadata(randomBoolean() ? null : deletionPolicy.snapshot());
    assertFalse(metadata.asMap().isEmpty());
    // do not check for correct files, we have enough tests for that above
    assertThat(metadata.getCommitUserData().get(Engine.SYNC_COMMIT_ID), equalTo(syncId));
    assertThat(metadata.getCommitUserData().get(Translog.TRANSLOG_GENERATION_KEY), equalTo(translogId));
    TestUtil.checkIndex(store.directory());
    assertDeleteContent(store, directoryService);
    IOUtils.close(store);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:StoreTests.java

示例11: ShardWriter

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的package包/类
/**
 * Constructor
 * @param fs
 * @param shard
 * @param tempDir
 * @param conf
 * @throws IOException
 */
public ShardWriter(FileSystem fs, Shard shard, String tempDir, Configuration conf)
    throws IOException {
  logger.info("Construct a shard writer");

  this.conf = conf;
  this.fs = fs;
  localFs = FileSystem.getLocal(conf);
  perm = new Path(shard.getDirectory());
  taxoPerm = new Path(shard.getDirectory() + ".taxonomy");
  String indexDir = tempDir + "/" + "index";
  String taxoDir = tempDir + "/" + "taxo";
  temp = new Path(indexDir);
  taxoTemp = new Path(taxoDir);

  if (localFs.exists(temp)) {
    File tempFile = new File(temp.getName());
    if (tempFile.exists()) {
      LindenReducer.deleteDir(tempFile);
    }
  }

  if (!fs.exists(perm)) {
    fs.mkdirs(perm);
  } else {
    moveToTrash(conf, perm);
    fs.mkdirs(perm);
  }

  if (!fs.exists(taxoPerm)) {
    fs.mkdirs(taxoPerm);
  } else {
    moveToTrash(conf, taxoPerm);
    fs.mkdirs(taxoPerm);
  }
  IndexWriterConfig config = new IndexWriterConfig(Version.LATEST, null);
  config.setIndexDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
  writer = new IndexWriter(FSDirectory.open(new File(indexDir)), config);
  taxoWriter = new DirectoryTaxonomyWriter(FSDirectory.open(new File(taxoDir)));
}
 
开发者ID:XiaoMi,项目名称:linden,代码行数:48,代码来源:ShardWriter.java

示例12: getIndexWriter

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的package包/类
/**
 * Ritorna l'indexwriter corretto per accedere all'indice.
 *
 * @param indexDir cartella indice
 * @param optimize true se si vuole ottimizzare
 * @param openMode indice aperto in append o in create
 * @param analyzer analyzer da utilizzare
 * @return IndexWriter
 * @throws Exception Eccezione eccezione
 */
public static IndexWriter getIndexWriter(Path indexDir, boolean optimize, IndexWriterConfig.OpenMode openMode, Analyzer analyzer) throws Exception {
    Directory fsDir = FSDirectory.open(indexDir);
    IndexWriterConfig iwConf = new IndexWriterConfig(analyzer);
    iwConf.setOpenMode(openMode);
    if (optimize) {
        iwConf.setIndexDeletionPolicy(new KeepLastIndexDeletionPolicy());
        iwConf.setUseCompoundFile(true);
    }
    return new IndexWriter(fsDir, iwConf);
}
 
开发者ID:fiohol,项目名称:theSemProject,代码行数:21,代码来源:IndexManager.java

示例13: createIndexWriterConfig

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的package包/类
@Override
protected IndexWriterConfig createIndexWriterConfig(OpenMode openMode) {
  IndexWriterConfig conf = super.createIndexWriterConfig(openMode);
  sdp = new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy());
  conf.setIndexDeletionPolicy(sdp);
  return conf;
}
 
开发者ID:europeana,项目名称:search,代码行数:8,代码来源:IndexAndTaxonomyRevision.java

示例14: testRevisionRelease

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的package包/类
@Test
public void testRevisionRelease() throws Exception {
  Directory indexDir = newDirectory();
  IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, null);
  conf.setIndexDeletionPolicy(new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy()));
  IndexWriter indexWriter = new IndexWriter(indexDir, conf);
  
  Directory taxoDir = newDirectory();
  SnapshotDirectoryTaxonomyWriter taxoWriter = new SnapshotDirectoryTaxonomyWriter(taxoDir);
  // we look to see that certain files are deleted:
  if (indexDir instanceof MockDirectoryWrapper) {
    ((MockDirectoryWrapper)indexDir).setEnableVirusScanner(false);
  }
  try {
    indexWriter.addDocument(newDocument(taxoWriter));
    indexWriter.commit();
    taxoWriter.commit();
    Revision rev1 = new IndexAndTaxonomyRevision(indexWriter, taxoWriter);
    // releasing that revision should not delete the files
    rev1.release();
    assertTrue(slowFileExists(indexDir, IndexFileNames.SEGMENTS + "_1"));
    assertTrue(slowFileExists(taxoDir, IndexFileNames.SEGMENTS + "_1"));
    
    rev1 = new IndexAndTaxonomyRevision(indexWriter, taxoWriter); // create revision again, so the files are snapshotted
    indexWriter.addDocument(newDocument(taxoWriter));
    indexWriter.commit();
    taxoWriter.commit();
    assertNotNull(new IndexAndTaxonomyRevision(indexWriter, taxoWriter));
    rev1.release(); // this release should trigger the delete of segments_1
    assertFalse(slowFileExists(indexDir, IndexFileNames.SEGMENTS + "_1"));
  } finally {
    IOUtils.close(indexWriter, taxoWriter, taxoDir, indexDir);
    if (indexDir instanceof MockDirectoryWrapper) {
      // set back to on for other tests
      ((MockDirectoryWrapper)indexDir).setEnableVirusScanner(true);
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:39,代码来源:IndexAndTaxonomyRevisionTest.java

示例15: setUp

import org.apache.lucene.index.IndexWriterConfig; //导入方法依赖的package包/类
@Before
@Override
public void setUp() throws Exception {
  super.setUp();
  sourceDir = newDirectory();
  IndexWriterConfig conf = newIndexWriterConfig(null);
  conf.setIndexDeletionPolicy(new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy()));
  sourceWriter = new IndexWriter(sourceDir, conf);
  replicator = new LocalReplicator();
}
 
开发者ID:europeana,项目名称:search,代码行数:11,代码来源:LocalReplicatorTest.java


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