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


Java SlowRAMDirectory类代码示例

本文整理汇总了Java中org.apache.lucene.facet.SlowRAMDirectory的典型用法代码示例。如果您正苦于以下问题:Java SlowRAMDirectory类的具体用法?Java SlowRAMDirectory怎么用?Java SlowRAMDirectory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testMemoryCacheSynchronization

import org.apache.lucene.facet.SlowRAMDirectory; //导入依赖的package包/类
/**
 * Test that a new TFC is only calculated and placed in memory (by two
 * threads who want it at the same time) only once.
 */
@Test
public void testMemoryCacheSynchronization() throws Exception {
  SlowRAMDirectory indexDir = new SlowRAMDirectory(-1, null);
  SlowRAMDirectory taxoDir = new SlowRAMDirectory(-1, null);

  // Write index using 'normal' directories
  IndexWriter w = new IndexWriter(indexDir, new IndexWriterConfig(
      TEST_VERSION_CURRENT, new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));
  DirectoryTaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir);
  FacetIndexingParams iParams = FacetIndexingParams.DEFAULT;
  // Add documents and facets
  for (int i = 0; i < 1000; i++) {
    addFacets(iParams, w, tw, "facet", Integer.toString(i));
  }
  w.close();
  tw.close();

  indexDir.setSleepMillis(1);
  taxoDir.setSleepMillis(1);

  IndexReader r = DirectoryReader.open(indexDir);
  DirectoryTaxonomyReader tr = new DirectoryTaxonomyReader(taxoDir);

  // Create and start threads. Thread1 should lock the cache and calculate
  // the TFC array. The second thread should block until the first is
  // done, then successfully retrieve from the cache without recalculating
  // or reading from disk.
  TFCThread tfcCalc1 = new TFCThread(r, tr, iParams);
  TFCThread tfcCalc2 = new TFCThread(r, tr, iParams);
  tfcCalc1.start();
  // Give thread 1 a head start to ensure correct sequencing for testing
  Thread.sleep(5);
  tfcCalc2.start();

  tfcCalc1.join();
  tfcCalc2.join();

  // Since this test ends up with references to the same TFC object, we
  // can only test the times to make sure that they are the same.
  assertRecomputed(tfcCalc1.tfc, 0, "thread 1 should recompute");
  assertRecomputed(tfcCalc2.tfc, 0, "thread 2 should recompute");
  assertTrue("Both results should be the same (as their inputs are the same objects)",
      tfcCalc1.tfc == tfcCalc2.tfc);

  r.close();
  tr.close();
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:52,代码来源:TestTotalFacetCountsCache.java


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