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


Java IndexCommit.getUserData方法代码示例

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


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

示例1: getIndexVersion

import org.apache.lucene.index.IndexCommit; //导入方法依赖的package包/类
private long[] getIndexVersion() {
  long version[] = new long[2];
  RefCounted<SolrIndexSearcher> searcher = core.getSearcher();
  try {
    final IndexCommit commit = searcher.get().getIndexReader().getIndexCommit();
    final Map<String,String> commitData = commit.getUserData();
    String commitTime = commitData.get(SolrIndexWriter.COMMIT_TIME_MSEC_KEY);
    if (commitTime != null) {
      version[0] = Long.parseLong(commitTime);
    }
    version[1] = commit.getGeneration();
  } catch (IOException e) {
    LOG.warn("Unable to get index version : ", e);
  } finally {
    searcher.decref();
  }
  return version;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:19,代码来源:ReplicationHandler.java

示例2: findIndexCommit

import org.apache.lucene.index.IndexCommit; //导入方法依赖的package包/类
public static IndexCommit findIndexCommit(Directory dir, String userData) throws IOException {
  Collection<IndexCommit> commits = DirectoryReader.listCommits(dir);
  for (final IndexCommit ic : commits) {
    Map<String,String> map = ic.getUserData();
    String ud = null;
    if (map != null) {
      ud = map.get(USER_DATA);
    }
    if (ud != null && ud.equals(userData)) {
      return ic;
    }
  }

  throw new IOException("index does not contain commit with userData: " + userData);
}
 
开发者ID:europeana,项目名称:search,代码行数:16,代码来源:OpenReaderTask.java

示例3: getCommitTimestamp

import org.apache.lucene.index.IndexCommit; //导入方法依赖的package包/类
public static long getCommitTimestamp(IndexCommit commit) throws IOException {
  final Map<String,String> commitData = commit.getUserData();
  String commitTime = commitData.get(SolrIndexWriter.COMMIT_TIME_MSEC_KEY);
  if (commitTime != null) {
    return Long.parseLong(commitTime);
  } else {
    return 0;
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:10,代码来源:IndexDeletionPolicyWrapper.java

示例4: testConcurrentWritesAndCommits

import org.apache.lucene.index.IndexCommit; //导入方法依赖的package包/类
public void testConcurrentWritesAndCommits() throws Exception {
    try (Store store = createStore();
         InternalEngine engine = new InternalEngine(config(defaultSettings, store, createTempDir(), newMergePolicy(),
                                                                 new SnapshotDeletionPolicy(NoDeletionPolicy.INSTANCE),
                                                                 IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, null))) {

        final int numIndexingThreads = scaledRandomIntBetween(3, 6);
        final int numDocsPerThread = randomIntBetween(500, 1000);
        final CyclicBarrier barrier = new CyclicBarrier(numIndexingThreads + 1);
        final List<Thread> indexingThreads = new ArrayList<>();
        // create N indexing threads to index documents simultaneously
        for (int threadNum = 0; threadNum < numIndexingThreads; threadNum++) {
            final int threadIdx = threadNum;
            Thread indexingThread = new Thread(() -> {
                try {
                    barrier.await(); // wait for all threads to start at the same time
                    // index random number of docs
                    for (int i = 0; i < numDocsPerThread; i++) {
                        final String id = "thread" + threadIdx + "#" + i;
                        ParsedDocument doc = testParsedDocument(id, "test", null, testDocument(), B_1, null);
                        engine.index(indexForDoc(doc));
                    }
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            });
            indexingThreads.add(indexingThread);
        }

        // start the indexing threads
        for (Thread thread : indexingThreads) {
            thread.start();
        }
        barrier.await(); // wait for indexing threads to all be ready to start

        // create random commit points
        boolean doneIndexing;
        do {
            doneIndexing = indexingThreads.stream().filter(Thread::isAlive).count() == 0;
            //engine.flush(); // flush and commit
        } while (doneIndexing == false);

        // now, verify all the commits have the correct docs according to the user commit data
        long prevLocalCheckpoint = SequenceNumbersService.NO_OPS_PERFORMED;
        long prevMaxSeqNo = SequenceNumbersService.NO_OPS_PERFORMED;
        for (IndexCommit commit : DirectoryReader.listCommits(store.directory())) {
            Map<String, String> userData = commit.getUserData();
            long localCheckpoint = userData.containsKey(SequenceNumbers.LOCAL_CHECKPOINT_KEY) ?
                                       Long.parseLong(userData.get(SequenceNumbers.LOCAL_CHECKPOINT_KEY)) :
                                       SequenceNumbersService.NO_OPS_PERFORMED;
            long maxSeqNo = userData.containsKey(SequenceNumbers.MAX_SEQ_NO) ?
                                Long.parseLong(userData.get(SequenceNumbers.MAX_SEQ_NO)) :
                                SequenceNumbersService.UNASSIGNED_SEQ_NO;
            // local checkpoint and max seq no shouldn't go backwards
            assertThat(localCheckpoint, greaterThanOrEqualTo(prevLocalCheckpoint));
            assertThat(maxSeqNo, greaterThanOrEqualTo(prevMaxSeqNo));
            try (IndexReader reader = DirectoryReader.open(commit)) {
                FieldStats stats = SeqNoFieldMapper.SeqNoDefaults.FIELD_TYPE.stats(reader);
                final long highestSeqNo;
                if (stats != null) {
                    highestSeqNo = (long) stats.getMaxValue();
                } else {
                    highestSeqNo = SequenceNumbersService.NO_OPS_PERFORMED;
                }
                // make sure localCheckpoint <= highest seq no found <= maxSeqNo
                assertThat(highestSeqNo, greaterThanOrEqualTo(localCheckpoint));
                assertThat(highestSeqNo, lessThanOrEqualTo(maxSeqNo));
                // make sure all sequence numbers up to and including the local checkpoint are in the index
                FixedBitSet seqNosBitSet = getSeqNosSet(reader, highestSeqNo);
                for (int i = 0; i <= localCheckpoint; i++) {
                    assertTrue("local checkpoint [" + localCheckpoint + "], _seq_no [" + i + "] should be indexed",
                               seqNosBitSet.get(i));
                }
            }
            prevLocalCheckpoint = localCheckpoint;
            prevMaxSeqNo = maxSeqNo;
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:80,代码来源:InternalEngineTests.java


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