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


Java Collector类代码示例

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


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

示例1: deriveCollectorName

import org.apache.lucene.search.Collector; //导入依赖的package包/类
/**
 * Creates a human-friendly representation of the Collector name.
 *
 * InternalBucket Collectors use the aggregation name in their toString() method,
 * which makes the profiled output a bit nicer.
 *
 * @param c The Collector to derive a name from
 * @return  A (hopefully) prettier name
 */
private String deriveCollectorName(Collector c) {
    String s = c.getClass().getSimpleName();

    // MutiCollector which wraps multiple BucketCollectors is generated
    // via an anonymous class, so this corrects the lack of a name by
    // asking the enclosingClass
    if (s.equals("")) {
        s = c.getClass().getEnclosingClass().getSimpleName();
    }

    // Aggregation collector toString()'s include the user-defined agg name
    if (reason.equals(CollectorResult.REASON_AGGREGATION) || reason.equals(CollectorResult.REASON_AGGREGATION_GLOBAL)) {
        s += ": [" + c.toString() + "]";
    }
    return s;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:InternalProfileCollector.java

示例2: countTestCase

import org.apache.lucene.search.Collector; //导入依赖的package包/类
private void countTestCase(Query query, IndexReader reader, boolean shouldCollect) throws Exception {
    TestSearchContext context = new TestSearchContext(null);
    context.parsedQuery(new ParsedQuery(query));
    context.setSize(0);
    context.setTask(new SearchTask(123L, "", "", "", null));

    IndexSearcher searcher = new IndexSearcher(reader);
    final AtomicBoolean collected = new AtomicBoolean();
    IndexSearcher contextSearcher = new IndexSearcher(reader) {
        protected void search(List<LeafReaderContext> leaves, Weight weight, Collector collector) throws IOException {
            collected.set(true);
            super.search(leaves, weight, collector);
        }
    };

    final boolean rescore = QueryPhase.execute(context, contextSearcher);
    assertFalse(rescore);
    assertEquals(searcher.count(query), context.queryResult().topDocs().totalHits);
    assertEquals(shouldCollect, collected.get());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:QueryPhaseTests.java

示例3: testPostFilterDisablesCountOptimization

import org.apache.lucene.search.Collector; //导入依赖的package包/类
public void testPostFilterDisablesCountOptimization() throws Exception {
    TestSearchContext context = new TestSearchContext(null);
    context.parsedQuery(new ParsedQuery(new MatchAllDocsQuery()));
    context.setSize(0);
    context.setTask(new SearchTask(123L, "", "", "", null));

    final AtomicBoolean collected = new AtomicBoolean();
    IndexSearcher contextSearcher = new IndexSearcher(new MultiReader()) {
        protected void search(List<LeafReaderContext> leaves, Weight weight, Collector collector) throws IOException {
            collected.set(true);
            super.search(leaves, weight, collector);
        }
    };

    QueryPhase.execute(context, contextSearcher);
    assertEquals(0, context.queryResult().topDocs().totalHits);
    assertFalse(collected.get());

    context.parsedPostFilter(new ParsedQuery(new MatchNoDocsQuery()));
    QueryPhase.execute(context, contextSearcher);
    assertEquals(0, context.queryResult().topDocs().totalHits);
    assertTrue(collected.get());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:QueryPhaseTests.java

示例4: testMinScoreDisablesCountOptimization

import org.apache.lucene.search.Collector; //导入依赖的package包/类
public void testMinScoreDisablesCountOptimization() throws Exception {
    TestSearchContext context = new TestSearchContext(null);
    context.parsedQuery(new ParsedQuery(new MatchAllDocsQuery()));
    context.setSize(0);
    context.setTask(new SearchTask(123L, "", "", "", null));

    final AtomicBoolean collected = new AtomicBoolean();
    IndexSearcher contextSearcher = new IndexSearcher(new MultiReader()) {
        protected void search(List<LeafReaderContext> leaves, Weight weight, Collector collector) throws IOException {
            collected.set(true);
            super.search(leaves, weight, collector);
        }
    };

    QueryPhase.execute(context, contextSearcher);
    assertEquals(0, context.queryResult().topDocs().totalHits);
    assertFalse(collected.get());

    context.minimumScore(1);
    QueryPhase.execute(context, contextSearcher);
    assertEquals(0, context.queryResult().topDocs().totalHits);
    assertTrue(collected.get());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:QueryPhaseTests.java

示例5: deriveCollectorName

import org.apache.lucene.search.Collector; //导入依赖的package包/类
/**
 * Creates a human-friendly representation of the Collector name.
 *
 * Bucket Collectors use the aggregation name in their toString() method,
 * which makes the profiled output a bit nicer.
 *
 * @param c The Collector to derive a name from
 * @return  A (hopefully) prettier name
 */
private String deriveCollectorName(Collector c) {
    String s = c.getClass().getSimpleName();

    // MutiCollector which wraps multiple BucketCollectors is generated
    // via an anonymous class, so this corrects the lack of a name by
    // asking the enclosingClass
    if (s.equals("")) {
        s = c.getClass().getEnclosingClass().getSimpleName();
    }

    // Aggregation collector toString()'s include the user-defined agg name
    if (reason.equals(CollectorResult.REASON_AGGREGATION) || reason.equals(CollectorResult.REASON_AGGREGATION_GLOBAL)) {
        s += ": [" + c.toString() + "]";
    }
    return s;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:26,代码来源:InternalProfileCollector.java

示例6: getInsanityWrapper

import org.apache.lucene.search.Collector; //导入依赖的package包/类
private Collector getInsanityWrapper(final String field, Collector collector) {
  SchemaField sf = searcher.getSchema().getFieldOrNull(field);
  if (sf != null && !sf.hasDocValues() && !sf.multiValued() && sf.getType().getNumberType() != null) {
    // it's a single-valued numeric field: we must currently create insanity :(
    // there isn't a GroupedFacetCollector that works on numerics right now...
    return new FilterCollector(collector) {
      @Override
      public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException {
        LeafReader insane = Insanity.wrapInsanity(context.reader(), field);
        return in.getLeafCollector(insane.getContext());
      }
    };
  } else {
    return collector;
  }
}
 
开发者ID:upenn-libraries,项目名称:solrplugins,代码行数:17,代码来源:SimpleFacets.java

示例7: searchAtomic

import org.apache.lucene.search.Collector; //导入依赖的package包/类
/**
 * Search all documents matching the passed query and pass the result on to
 * the provided {@link Consumer}.
 *
 * @param aQuery
 *        Query to execute. May not be <code>null</code>-
 * @param aCollector
 *        The Lucene collector to be used. May not be <code>null</code>.
 * @throws IOException
 *         On Lucene error
 * @see #getAllDocuments(Query)
 */
public void searchAtomic (@Nonnull final Query aQuery, @Nonnull final Collector aCollector) throws IOException
{
  ValueEnforcer.notNull (aQuery, "Query");
  ValueEnforcer.notNull (aCollector, "Collector");

  m_aLucene.runAtomic ( () -> {
    final IndexSearcher aSearcher = m_aLucene.getSearcher ();
    if (aSearcher != null)
    {
      if (s_aLogger.isDebugEnabled ())
        s_aLogger.debug ("Searching Lucene: " + aQuery);

      // Search all documents, collect them
      _timedSearch ( () -> aSearcher.search (aQuery, aCollector), aQuery);
    }
    else
      s_aLogger.error ("Failed to obtain IndexSearcher");
  });
}
 
开发者ID:phax,项目名称:peppol-directory,代码行数:32,代码来源:PDStorageManager.java

示例8: getAllContainedParticipantIDs

import org.apache.lucene.search.Collector; //导入依赖的package包/类
@Nonnull
@ReturnsMutableCopy
public ICommonsSortedSet <IParticipantIdentifier> getAllContainedParticipantIDs ()
{
  final ICommonsSortedSet <IParticipantIdentifier> aTargetSet = new CommonsTreeSet <> ();
  final Query aQuery = PDQueryManager.andNotDeleted (new MatchAllDocsQuery ());
  try
  {
    final ObjIntConsumer <Document> aConsumer = (aDoc,
                                                 nDocID) -> aTargetSet.add (PDField.PARTICIPANT_ID.getDocValue (aDoc));
    final Collector aCollector = new AllDocumentsCollector (m_aLucene, aConsumer);
    searchAtomic (aQuery, aCollector);
  }
  catch (final IOException ex)
  {
    s_aLogger.error ("Error searching for documents with query " + aQuery, ex);
  }
  return aTargetSet;
}
 
开发者ID:phax,项目名称:peppol-directory,代码行数:20,代码来源:PDStorageManager.java

示例9: collectHit

import org.apache.lucene.search.Collector; //导入依赖的package包/类
private void collectHit(Collector collector, Collector[] sidewaysCollectors) throws IOException {
  //if (DEBUG) {
  //  System.out.println("      hit");
  //}

  collector.collect(collectDocID);
  if (drillDownCollector != null) {
    drillDownCollector.collect(collectDocID);
  }

  // TODO: we could "fix" faceting of the sideways counts
  // to do this "union" (of the drill down hits) in the
  // end instead:

  // Tally sideways counts:
  for (int dim=0;dim<sidewaysCollectors.length;dim++) {
    sidewaysCollectors[dim].collect(collectDocID);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:DrillSidewaysScorer.java

示例10: score

import org.apache.lucene.search.Collector; //导入依赖的package包/类
@Override
public boolean score(Collector collector, int max) throws IOException {
  FakeScorer fakeScorer = new FakeScorer();
  collector.setScorer(fakeScorer);
  if (doc == -1) {
    doc = nextDocOutOfOrder();
  }
  while(doc < max) {
    fakeScorer.doc = doc;
    fakeScorer.score = scores[ords[scoreUpto]];
    collector.collect(doc);
    doc = nextDocOutOfOrder();
  }

  return doc != DocsEnum.NO_MORE_DOCS;
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:TermsIncludingScoreQuery.java

示例11: testNullCollectors

import org.apache.lucene.search.Collector; //导入依赖的package包/类
@Test
public void testNullCollectors() throws Exception {
  // Tests that the collector rejects all null collectors.
  try {
    MultiCollector.wrap(null, null);
    fail("only null collectors should not be supported");
  } catch (IllegalArgumentException e) {
    // expected
  }

  // Tests that the collector handles some null collectors well. If it
  // doesn't, an NPE would be thrown.
  Collector c = MultiCollector.wrap(new DummyCollector(), null, new DummyCollector());
  assertTrue(c instanceof MultiCollector);
  assertTrue(c.acceptsDocsOutOfOrder());
  c.collect(1);
  c.setNextReader(null);
  c.setScorer(null);
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:MultiCollectorTest.java

示例12: testCollector

import org.apache.lucene.search.Collector; //导入依赖的package包/类
@Test
public void testCollector() throws Exception {
  // Tests that the collector delegates calls to input collectors properly.

  // Tests that the collector handles some null collectors well. If it
  // doesn't, an NPE would be thrown.
  DummyCollector[] dcs = new DummyCollector[] { new DummyCollector(), new DummyCollector() };
  Collector c = MultiCollector.wrap(dcs);
  assertTrue(c.acceptsDocsOutOfOrder());
  c.collect(1);
  c.setNextReader(null);
  c.setScorer(null);

  for (DummyCollector dc : dcs) {
    assertTrue(dc.acceptsDocsOutOfOrderCalled);
    assertTrue(dc.collectCalled);
    assertTrue(dc.setNextReaderCalled);
    assertTrue(dc.setScorerCalled);
  }

}
 
开发者ID:europeana,项目名称:search,代码行数:22,代码来源:MultiCollectorTest.java

示例13: getDocSetScore

import org.apache.lucene.search.Collector; //导入依赖的package包/类
private DocSet getDocSetScore(List<Query> queries) throws IOException {
  Query main = queries.remove(0);
  ProcessedFilter pf = getProcessedFilter(null, queries);
  DocSetCollector setCollector = new DocSetCollector(maxDoc()>>6, maxDoc());
  Collector collector = setCollector;
  if (pf.postFilter != null) {
    pf.postFilter.setLastDelegate(collector);
    collector = pf.postFilter;
  }

  search(main, pf.filter, collector);

  if(collector instanceof DelegatingCollector) {
    ((DelegatingCollector) collector).finish();
  }

  DocSet docSet = setCollector.getDocSet();
  return docSet;
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:SolrIndexSearcher.java

示例14: execute

import org.apache.lucene.search.Collector; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void execute() throws IOException {
  final int nrOfCommands = commands.size();
  List<Collector> collectors = new ArrayList<>(nrOfCommands);
  for (Command command : commands) {
    collectors.addAll(command.create());
  }

  ProcessedFilter filter = searcher.getProcessedFilter
    (queryCommand.getFilter(), queryCommand.getFilterList());
  Query query = QueryUtils.makeQueryable(queryCommand.getQuery());

  if (truncateGroups) {
    docSet = computeGroupedDocSet(query, filter, collectors);
  } else if (needDocset) {
    docSet = computeDocSet(query, filter, collectors);
  } else if (!collectors.isEmpty()) {
    searchWithTimeLimiter(query, filter, MultiCollector.wrap(collectors.toArray(new Collector[nrOfCommands])));
  } else {
    searchWithTimeLimiter(query, filter, null);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:CommandHandler.java

示例15: GroupExpandCollector

import org.apache.lucene.search.Collector; //导入依赖的package包/类
public GroupExpandCollector(SortedDocValues docValues, FixedBitSet groupBits, IntOpenHashSet collapsedSet, int limit, Sort sort) throws IOException {
  int numGroups = collapsedSet.size();
  groups = new IntObjectOpenHashMap<>(numGroups * 2);
  collectors = new ArrayList<>();
  DocIdSetIterator iterator = groupBits.iterator();
  int group;
  while ((group = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
    Collector collector = (sort == null) ? TopScoreDocCollector.create(limit, true) : TopFieldCollector.create(sort, limit, false, false, false, true);
    groups.put(group, collector);
    collectors.add(collector);
  }

  this.collapsedSet = collapsedSet;
  this.groupBits = groupBits;
  this.docValues = docValues;
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:ExpandComponent.java


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