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


Java AtomicReader.close方法代码示例

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


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

示例1: testDocsEnumStart

import org.apache.lucene.index.AtomicReader; //导入方法依赖的package包/类
public void testDocsEnumStart() throws Exception {
  Analyzer analyzer = new MockAnalyzer(random());
  MemoryIndex memory = new MemoryIndex(random().nextBoolean(),  random().nextInt(50) * 1024 * 1024);
  memory.addField("foo", "bar", analyzer);
  AtomicReader reader = (AtomicReader) memory.createSearcher().getIndexReader();
  DocsEnum disi = TestUtil.docs(random(), reader, "foo", new BytesRef("bar"), null, null, DocsEnum.FLAG_NONE);
  int docid = disi.docID();
  assertEquals(-1, docid);
  assertTrue(disi.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
  
  // now reuse and check again
  TermsEnum te = reader.terms("foo").iterator(null);
  assertTrue(te.seekExact(new BytesRef("bar")));
  disi = te.docs(null, disi, DocsEnum.FLAG_NONE);
  docid = disi.docID();
  assertEquals(-1, docid);
  assertTrue(disi.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
  reader.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:MemoryIndexTest.java

示例2: checkOnlineClassification

import org.apache.lucene.index.AtomicReader; //导入方法依赖的package包/类
protected void checkOnlineClassification(Classifier<T> classifier, String inputDoc, T expectedResult, Analyzer analyzer, String textFieldName, String classFieldName, Query query) throws Exception {
  AtomicReader atomicReader = null;
  try {
    populateSampleIndex(analyzer);
    atomicReader = SlowCompositeReaderWrapper.wrap(indexWriter.getReader());
    classifier.train(atomicReader, textFieldName, classFieldName, analyzer, query);
    ClassificationResult<T> classificationResult = classifier.assignClass(inputDoc);
    assertNotNull(classificationResult.getAssignedClass());
    assertEquals("got an assigned class of " + classificationResult.getAssignedClass(), expectedResult, classificationResult.getAssignedClass());
    assertTrue("got a not positive score " + classificationResult.getScore(), classificationResult.getScore() > 0);
    updateSampleIndex(analyzer);
    ClassificationResult<T> secondClassificationResult = classifier.assignClass(inputDoc);
    assertEquals(classificationResult.getAssignedClass(), secondClassificationResult.getAssignedClass());
    assertEquals(Double.valueOf(classificationResult.getScore()), Double.valueOf(secondClassificationResult.getScore()));

  } finally {
    if (atomicReader != null)
      atomicReader.close();
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:ClassificationTestBase.java

示例3: testGetFilterHandleNumericParseError

import org.apache.lucene.index.AtomicReader; //导入方法依赖的package包/类
public void testGetFilterHandleNumericParseError() throws Exception {
  NumericRangeFilterBuilder filterBuilder = new NumericRangeFilterBuilder();
  filterBuilder.setStrictMode(false);

  String xml = "<NumericRangeFilter fieldName='AGE' type='int' lowerTerm='-1' upperTerm='NaN'/>";
  Document doc = getDocumentFromString(xml);
  Filter filter = filterBuilder.getFilter(doc.getDocumentElement());
  Directory ramDir = newDirectory();
  IndexWriter writer = new IndexWriter(ramDir, newIndexWriterConfig(null));
  writer.commit();
  try {
    AtomicReader reader = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(ramDir));
    try {
      assertNull(filter.getDocIdSet(reader.getContext(), reader.getLiveDocs()));
    }
    finally {
      reader.close();
    }
  }
  finally {
    writer.commit();
    writer.close();
    ramDir.close();
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:TestNumericRangeFilterBuilder.java

示例4: testDocsAndPositionsEnumStart

import org.apache.lucene.index.AtomicReader; //导入方法依赖的package包/类
public void testDocsAndPositionsEnumStart() throws Exception {
  Analyzer analyzer = new MockAnalyzer(random());
  int numIters = atLeast(3);
  MemoryIndex memory = new MemoryIndex(true,  random().nextInt(50) * 1024 * 1024);
  for (int i = 0; i < numIters; i++) { // check reuse
    memory.addField("foo", "bar", analyzer);
    AtomicReader reader = (AtomicReader) memory.createSearcher().getIndexReader();
    assertEquals(1, reader.terms("foo").getSumTotalTermFreq());
    DocsAndPositionsEnum disi = reader.termPositionsEnum(new Term("foo", "bar"));
    int docid = disi.docID();
    assertEquals(-1, docid);
    assertTrue(disi.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
    assertEquals(0, disi.nextPosition());
    assertEquals(0, disi.startOffset());
    assertEquals(3, disi.endOffset());
    
    // now reuse and check again
    TermsEnum te = reader.terms("foo").iterator(null);
    assertTrue(te.seekExact(new BytesRef("bar")));
    disi = te.docsAndPositions(null, disi);
    docid = disi.docID();
    assertEquals(-1, docid);
    assertTrue(disi.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
    reader.close();
    memory.reset();
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:28,代码来源:MemoryIndexTest.java

示例5: checkCorrectClassification

import org.apache.lucene.index.AtomicReader; //导入方法依赖的package包/类
protected void checkCorrectClassification(Classifier<T> classifier, String inputDoc, T expectedResult, Analyzer analyzer, String textFieldName, String classFieldName, Query query) throws Exception {
  AtomicReader atomicReader = null;
  try {
    populateSampleIndex(analyzer);
    atomicReader = SlowCompositeReaderWrapper.wrap(indexWriter.getReader());
    classifier.train(atomicReader, textFieldName, classFieldName, analyzer, query);
    ClassificationResult<T> classificationResult = classifier.assignClass(inputDoc);
    assertNotNull(classificationResult.getAssignedClass());
    assertEquals("got an assigned class of " + classificationResult.getAssignedClass(), expectedResult, classificationResult.getAssignedClass());
    assertTrue("got a not positive score " + classificationResult.getScore(), classificationResult.getScore() > 0);
  } finally {
    if (atomicReader != null)
      atomicReader.close();
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:16,代码来源:ClassificationTestBase.java

示例6: checkPerformance

import org.apache.lucene.index.AtomicReader; //导入方法依赖的package包/类
protected void checkPerformance(Classifier<T> classifier, Analyzer analyzer, String classFieldName) throws Exception {
  AtomicReader atomicReader = null;
  long trainStart = System.currentTimeMillis();
  try {
    populatePerformanceIndex(analyzer);
    atomicReader = SlowCompositeReaderWrapper.wrap(indexWriter.getReader());
    classifier.train(atomicReader, textFieldName, classFieldName, analyzer);
    long trainEnd = System.currentTimeMillis();
    long trainTime = trainEnd - trainStart;
    assertTrue("training took more than 2 mins : " + trainTime / 1000 + "s", trainTime < 120000);
  } finally {
    if (atomicReader != null)
      atomicReader.close();
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:16,代码来源:ClassificationTestBase.java


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