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


Java Codec.forName方法代码示例

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


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

示例1: test

import org.apache.lucene.codecs.Codec; //导入方法依赖的package包/类
public void test() throws Exception {
  Codec codec = Codec.forName("Lucene3x");
  assertTrue(codec instanceof PreFlexRWCodec);
}
 
开发者ID:europeana,项目名称:search,代码行数:5,代码来源:TestImpersonation.java

示例2: testDocsStuckInRAMForever

import org.apache.lucene.codecs.Codec; //导入方法依赖的package包/类
public void testDocsStuckInRAMForever() throws Exception {
  Directory dir = newDirectory();
  IndexWriterConfig iwc = new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
  iwc.setRAMBufferSizeMB(.2);
  Codec codec = Codec.forName("Lucene410");
  iwc.setCodec(codec);
  iwc.setMergePolicy(NoMergePolicy.INSTANCE);
  final IndexWriter w = new IndexWriter(dir, iwc);
  final CountDownLatch startingGun = new CountDownLatch(1);
  Thread[] threads = new Thread[2];
  for(int i=0;i<threads.length;i++) {
    final int threadID = i;
    threads[i] = new Thread() {
        @Override
        public void run() {
          try {
            startingGun.await();
            for(int j=0;j<1000;j++) {
              Document doc = new Document();
              doc.add(newStringField("field", "threadID" + threadID, Field.Store.NO));
              w.addDocument(doc);
            }
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
      };
    threads[i].start();
  }

  startingGun.countDown();
  for(Thread t : threads) {
    t.join();
  }

  Set<String> segSeen = new HashSet<>();
  int thread0Count = 0;
  int thread1Count = 0;

  // At this point the writer should have 2 thread states w/ docs; now we index with only 1 thread until we see all 1000 thread0 & thread1
  // docs flushed.  If the writer incorrectly holds onto previously indexed docs forever then this will run forever:
  while (thread0Count < 1000 || thread1Count < 1000) {
    Document doc = new Document();
    doc.add(newStringField("field", "threadIDmain", Field.Store.NO));
    w.addDocument(doc);

    for(String fileName : dir.listAll()) {
      if (fileName.endsWith(".si")) {
        String segName = IndexFileNames.parseSegmentName(fileName);
        if (segSeen.contains(segName) == false) {
          segSeen.add(segName);
          SegmentInfo si = new Lucene46SegmentInfoFormat().getSegmentInfoReader().read(dir, segName, IOContext.DEFAULT);
          si.setCodec(codec);
          SegmentCommitInfo sci = new SegmentCommitInfo(si, 0, -1, -1, -1);
          SegmentReader sr = new SegmentReader(sci, 1, IOContext.DEFAULT);
          try {
            thread0Count += sr.docFreq(new Term("field", "threadID0"));
            thread1Count += sr.docFreq(new Term("field", "threadID1"));
          } finally {
            sr.close();
          }
        }
      }
    }
  }

  w.close();
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:70,代码来源:TestIndexWriterThreadsToSegments.java

示例3: setUp

import org.apache.lucene.codecs.Codec; //导入方法依赖的package包/类
@Override
public void setUp() throws Exception {
  super.setUp();

  // for now its SimpleText vs Lucene410(random postings format)
  // as this gives the best overall coverage. when we have more
  // codecs we should probably pick 2 from Codec.availableCodecs()
  
  leftCodec = Codec.forName("SimpleText");
  rightCodec = new RandomCodec(random());

  leftDir = newDirectory();
  rightDir = newDirectory();

  long seed = random().nextLong();

  // must use same seed because of random payloads, etc
  int maxTermLength = TestUtil.nextInt(random(), 1, IndexWriter.MAX_TERM_LENGTH);
  MockAnalyzer leftAnalyzer = new MockAnalyzer(new Random(seed));
  leftAnalyzer.setMaxTokenLength(maxTermLength);
  MockAnalyzer rightAnalyzer = new MockAnalyzer(new Random(seed));
  rightAnalyzer.setMaxTokenLength(maxTermLength);

  // but these can be different
  // TODO: this turns this into a really big test of Multi*, is that what we want?
  IndexWriterConfig leftConfig = newIndexWriterConfig(leftAnalyzer);
  leftConfig.setCodec(leftCodec);
  // preserve docids
  leftConfig.setMergePolicy(newLogMergePolicy());

  IndexWriterConfig rightConfig = newIndexWriterConfig(rightAnalyzer);
  rightConfig.setCodec(rightCodec);
  // preserve docids
  rightConfig.setMergePolicy(newLogMergePolicy());

  // must use same seed because of random docvalues fields, etc
  RandomIndexWriter leftWriter = new RandomIndexWriter(new Random(seed), leftDir, leftConfig);
  RandomIndexWriter rightWriter = new RandomIndexWriter(new Random(seed), rightDir, rightConfig);
  
  int numdocs = atLeast(100);
  createRandomIndex(numdocs, leftWriter, seed);
  createRandomIndex(numdocs, rightWriter, seed);

  leftReader = maybeWrapReader(leftWriter.getReader());
  leftWriter.close();
  rightReader = maybeWrapReader(rightWriter.getReader());
  rightWriter.close();
  
  // check that our readers are valid
  TestUtil.checkReader(leftReader);
  TestUtil.checkReader(rightReader);
  
  info = "left: " + leftCodec.toString() + " / right: " + rightCodec.toString();
}
 
开发者ID:europeana,项目名称:search,代码行数:55,代码来源:TestDuelingCodecs.java

示例4: testLookup

import org.apache.lucene.codecs.Codec; //导入方法依赖的package包/类
public void testLookup() {
  Codec codec = Codec.forName("Lucene410");
  assertEquals("Lucene410", codec.getName());
}
 
开发者ID:europeana,项目名称:search,代码行数:5,代码来源:TestNamedSPILoader.java

示例5: testBogusLookup

import org.apache.lucene.codecs.Codec; //导入方法依赖的package包/类
public void testBogusLookup() {
  try {
    Codec.forName("dskfdskfsdfksdfdsf");
    fail();
  } catch (IllegalArgumentException expected) {}
}
 
开发者ID:europeana,项目名称:search,代码行数:7,代码来源:TestNamedSPILoader.java


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