org.apache.lucene.search.TopDocsCollector Java Examples

The following examples show how to use org.apache.lucene.search.TopDocsCollector. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AlfrescoReRankQParserPlugin.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
public TopDocsCollector getTopDocsCollector(int len, QueryCommand cmd, IndexSearcher searcher) throws IOException {

            if(this.boostedPriority == null) {
                SolrRequestInfo info = SolrRequestInfo.getRequestInfo();
                if(info != null) {
                    Map context = info.getReq().getContext();
                    this.boostedPriority = (Map<BytesRef, Integer>)context.get(QueryElevationComponent.BOOSTED_PRIORITY);
                }
            }

            return new ReRankCollector(reRankDocs, length, reRankQuery, reRankWeight, cmd, searcher, boostedPriority, scale);
        }
 
Example #2
Source File: EarlyTerminationCollector.java    From linden with Apache License 2.0 5 votes vote down vote up
public EarlyTerminationCollector(TopDocsCollector collector, Sort sort, int numDocsToCollectPerSortedSegment) {
  if (numDocsToCollectPerSortedSegment <= 0) {
    throw new IllegalStateException(
        "numDocsToCollectPerSortedSegment must always be > 0, got " + numDocsToCollectPerSortedSegment);
  }
  this.collector = collector;
  this.sort = sort;
  this.numDocsToCollectPerSortedSegment = numDocsToCollectPerSortedSegment;
}
 
Example #3
Source File: LindenDocsCollector.java    From linden with Apache License 2.0 5 votes vote down vote up
public LindenDocsCollector(Collector collector) {
  if (!(collector instanceof TopDocsCollector) && !(collector instanceof EarlyTerminationCollector)) {
    throw new RuntimeException("Unsupported collector class in LindenDocsCollector: " + collector.getClass().getName());
  }
  hitCollector = collector;
  wrappedCollector = collector;
}
 
Example #4
Source File: AbstractReRankQuery.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public TopDocsCollector getTopDocsCollector(int len, QueryCommand cmd, IndexSearcher searcher) throws IOException {
  if(this.boostedPriority == null) {
    SolrRequestInfo info = SolrRequestInfo.getRequestInfo();
    if(info != null) {
      Map context = info.getReq().getContext();
      this.boostedPriority = (Set<BytesRef>)context.get(QueryElevationComponent.BOOSTED);
    }
  }

  return new ReRankCollector(reRankDocs, len, reRankQueryRescorer, cmd, searcher, boostedPriority);
}
 
Example #5
Source File: ExportQParserPlugin.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"rawtypes"})
public TopDocsCollector getTopDocsCollector(int len,
                                            QueryCommand cmd,
                                            IndexSearcher searcher) throws IOException {
  int leafCount = searcher.getTopReaderContext().leaves().size();
  FixedBitSet[] sets = new FixedBitSet[leafCount];
  return new ExportCollector(sets);
}
 
Example #6
Source File: RankQueryTestPlugin.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"rawtypes"})
public TopDocsCollector getTopDocsCollector(int len, QueryCommand cmd, IndexSearcher searcher) {
  if(collector == 0)
    return new TestCollector(null);
  else
    return new TestCollector1(null);
}
 
Example #7
Source File: TopHitsAggregator.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
TopDocsAndLeafCollector(TopDocsCollector<?> topLevelCollector) {
    this.topLevelCollector = topLevelCollector;
}
 
Example #8
Source File: BestDocsDeferringCollector.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
protected TopDocsCollector<? extends ScoreDoc> createTopDocsCollector(int size) throws IOException {
    return TopScoreDocCollector.create(size);
}
 
Example #9
Source File: DiversifiedMapSamplerAggregator.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
protected TopDocsCollector<ScoreDocKey> createTopDocsCollector(int size) {
    return new ValuesDiversifiedTopDocsCollector(size, maxDocsPerValue);
}
 
Example #10
Source File: DiversifiedBytesHashSamplerAggregator.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
protected TopDocsCollector<ScoreDocKey> createTopDocsCollector(int size) {
    return new ValuesDiversifiedTopDocsCollector(size, maxDocsPerValue);
}
 
Example #11
Source File: DiversifiedOrdinalsSamplerAggregator.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
protected TopDocsCollector<ScoreDocKey> createTopDocsCollector(int size) {
    return new ValuesDiversifiedTopDocsCollector(size, maxDocsPerValue);
}
 
Example #12
Source File: DiversifiedNumericSamplerAggregator.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
protected TopDocsCollector<ScoreDocKey> createTopDocsCollector(int size) {
    return new ValuesDiversifiedTopDocsCollector(size, maxDocsPerValue);
}
 
Example #13
Source File: LindenDocsCollector.java    From linden with Apache License 2.0 4 votes vote down vote up
public TopDocs topDocs() {
  if (hitCollector instanceof TopDocsCollector) {
    return ((TopDocsCollector) hitCollector).topDocs();
  }
  return ((EarlyTerminationCollector) hitCollector).topDocs();
}
 
Example #14
Source File: BlockGroupingCollector.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/** Returns the grouped results.  Returns null if the
 *  number of groups collected is &lt;= groupOffset.
 *
 *  <p><b>NOTE</b>: This collector is unable to compute
 *  the groupValue per group so it will always be null.
 *  This is normally not a problem, as you can obtain the
 *  value just like you obtain other values for each
 *  matching document (eg, via stored fields, via
 *  DocValues, etc.)
 *
 *  @param withinGroupSort The {@link Sort} used to sort
 *    documents within each group.
 *  @param groupOffset Which group to start from
 *  @param withinGroupOffset Which document to start from
 *    within each group
 *  @param maxDocsPerGroup How many top documents to keep
 *     within each group.
 */
public TopGroups<?> getTopGroups(Sort withinGroupSort, int groupOffset, int withinGroupOffset, int maxDocsPerGroup) throws IOException {

  //if (queueFull) {
  //System.out.println("getTopGroups groupOffset=" + groupOffset + " topNGroups=" + topNGroups);
  //}
  if (subDocUpto != 0) {
    processGroup();
  }
  if (groupOffset >= groupQueue.size()) {
    return null;
  }
  int totalGroupedHitCount = 0;

  final ScoreAndDoc fakeScorer = new ScoreAndDoc();

  float maxScore = Float.MIN_VALUE;

  @SuppressWarnings({"unchecked","rawtypes"})
  final GroupDocs<Object>[] groups = new GroupDocs[groupQueue.size() - groupOffset];
  for(int downTo=groupQueue.size()-groupOffset-1;downTo>=0;downTo--) {
    final OneGroup og = groupQueue.pop();

    // At this point we hold all docs w/ in each group,
    // unsorted; we now sort them:
    final TopDocsCollector<?> collector;
    if (withinGroupSort.equals(Sort.RELEVANCE)) {
      // Sort by score
      if (!needsScores) {
        throw new IllegalArgumentException("cannot sort by relevance within group: needsScores=false");
      }
      collector = TopScoreDocCollector.create(maxDocsPerGroup, Integer.MAX_VALUE);
    } else {
      // Sort by fields
      collector = TopFieldCollector.create(withinGroupSort, maxDocsPerGroup, Integer.MAX_VALUE); // TODO: disable exact counts?
    }

    float groupMaxScore = needsScores ? Float.NEGATIVE_INFINITY : Float.NaN;
    LeafCollector leafCollector = collector.getLeafCollector(og.readerContext);
    leafCollector.setScorer(fakeScorer);
    for(int docIDX=0;docIDX<og.count;docIDX++) {
      final int doc = og.docs[docIDX];
      fakeScorer.doc = doc;
      if (needsScores) {
        fakeScorer.score = og.scores[docIDX];
        groupMaxScore = Math.max(groupMaxScore, fakeScorer.score);
      }
      leafCollector.collect(doc);
    }
    totalGroupedHitCount += og.count;

    final Object[] groupSortValues;

    groupSortValues = new Comparable<?>[comparators.length];
    for(int sortFieldIDX=0;sortFieldIDX<comparators.length;sortFieldIDX++) {
      groupSortValues[sortFieldIDX] = comparators[sortFieldIDX].value(og.comparatorSlot);
    }

    final TopDocs topDocs = collector.topDocs(withinGroupOffset, maxDocsPerGroup);

    // TODO: we could aggregate scores across children
    // by Sum/Avg instead of passing NaN:
    groups[downTo] = new GroupDocs<>(Float.NaN,
                                           groupMaxScore,
                                           new TotalHits(og.count, TotalHits.Relation.EQUAL_TO),
                                           topDocs.scoreDocs,
                                           null,
                                           groupSortValues);
    maxScore = Math.max(maxScore, groupMaxScore);
  }

  /*
  while (groupQueue.size() != 0) {
    final OneGroup og = groupQueue.pop();
    //System.out.println("  leftover: og ord=" + og.groupOrd + " count=" + og.count);
    totalGroupedHitCount += og.count;
  }
  */

  return new TopGroups<>(new TopGroups<>(groupSort.getSort(),
                                     withinGroupSort.getSort(),
                                     totalHitCount, totalGroupedHitCount, groups, maxScore),
                       totalGroupCount);
}
 
Example #15
Source File: TopGroupsCollector.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public TopDocsAndMaxScoreCollector(boolean sortedByScore, TopDocsCollector<?> topDocsCollector, MaxScoreCollector maxScoreCollector) {
  super(MultiCollector.wrap(topDocsCollector, maxScoreCollector));
  this.sortedByScore = sortedByScore;
  this.topDocsCollector = topDocsCollector;
  this.maxScoreCollector = maxScoreCollector;
}
 
Example #16
Source File: RankQuery.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({"rawtypes"})
public abstract TopDocsCollector getTopDocsCollector(int len, QueryCommand cmd, IndexSearcher searcher) throws IOException;