Java 类org.apache.lucene.search.TimeLimitingCollector 实例源码

项目:t4f-data    文件:TimeLimitingCollectorTest.java   
public void testTimeLimitingCollector() throws Exception {
  Directory dir = TestUtil.getBookIndexDirectory();
  IndexSearcher searcher = new IndexSearcher(dir);
  Query q = new MatchAllDocsQuery();
  int numAllBooks = TestUtil.hitCount(searcher, q);

  TopScoreDocCollector topDocs = TopScoreDocCollector.create(10, false);
  Collector collector = new TimeLimitingCollector(topDocs,  // #A
                                                  1000);    // #A
  try {
    searcher.search(q, collector);
    assertEquals(numAllBooks, topDocs.getTotalHits());  // #B
  } catch (TimeExceededException tee) {                 // #C
    LOGGER.info("Too much time taken.");         // #C
  }                                                     // #C
  searcher.close();
  dir.close();
}
项目:elasticsearch_my    文件:Lucene.java   
/**
 * Wraps <code>delegate</code> with a time limited collector with a timeout of <code>timeoutInMillis</code>
 */
public static final TimeLimitingCollector wrapTimeLimitingCollector(final Collector delegate, final Counter counter, long timeoutInMillis) {
    return new TimeLimitingCollector(delegate, counter, timeoutInMillis);
}