Java Code Examples for org.apache.lucene.search.Scorable

The following examples show how to use org.apache.lucene.search.Scorable. These examples are extracted from open source projects. 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 Project: lucene-solr   Source File: ScoringMatch.java    License: Apache License 2.0 6 votes vote down vote up
public static final MatcherFactory<ScoringMatch> matchWithSimilarity(Similarity similarity) {
  return searcher -> {
    searcher.setSimilarity(similarity);
    return new CollectingMatcher<ScoringMatch>(searcher, ScoreMode.COMPLETE) {
      @Override
      protected ScoringMatch doMatch(String queryId, int doc, Scorable scorer) throws IOException {
        float score = scorer.score();
        if (score > 0)
          return new ScoringMatch(queryId, score);
        return null;
      }

      @Override
      public ScoringMatch resolve(ScoringMatch match1, ScoringMatch match2) {
        return new ScoringMatch(match1.getQueryId(), match1.getScore() + match2.getScore());
      }
    };
  };
}
 
Example 2
Source Project: lucene-solr   Source File: ExportQParserPlugin.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException {
  final FixedBitSet set = new FixedBitSet(context.reader().maxDoc());
  this.sets[context.ord] = set;
  return new LeafCollector() {
    
    @Override
    public void setScorer(Scorable scorer) throws IOException {}
    
    @Override
    public void collect(int docId) throws IOException{
      ++totalHits;
      set.set(docId);
    }
  };
}
 
Example 3
Source Project: lucene-solr   Source File: RankQueryTestPlugin.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException {
  final int base = context.docBase;
  final NumericDocValues values = DocValues.getNumeric(context.reader(), "sort_i");
  return new LeafCollector() {
    
    @Override
    public void setScorer(Scorable scorer) throws IOException {}
    
    public void collect(int doc) throws IOException {
      long value;
      if (values.advanceExact(doc)) {
        value = values.longValue();
      } else {
        value = 0;
      }
      list.add(new ScoreDoc(doc+base, (float) value));
    }
  };
}
 
Example 4
Source Project: lucene-solr   Source File: AllGroupHeadsCollector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setScorer(Scorable scorer) throws IOException {
  this.scorer = scorer;
  for (GroupHead<T> head : heads.values()) {
    head.setScorer(scorer);
  }
}
 
Example 5
Source Project: lucene-solr   Source File: AllGroupHeadsCollector.java    License: Apache License 2.0 5 votes vote down vote up
protected SortingGroupHead(Sort sort, T groupValue, int doc, LeafReaderContext context, Scorable scorer) throws IOException {
  super(groupValue, doc, context.docBase);
  final SortField[] sortFields = sort.getSort();
  comparators = new FieldComparator[sortFields.length];
  leafComparators = new LeafFieldComparator[sortFields.length];
  for (int i = 0; i < sortFields.length; i++) {
    comparators[i] = sortFields[i].getComparator(1, i);
    leafComparators[i] = comparators[i].getLeafComparator(context);
    leafComparators[i].setScorer(scorer);
    leafComparators[i].copy(0, doc);
    leafComparators[i].setBottom(0);
  }
}
 
Example 6
Source Project: lucene-solr   Source File: BlockGroupingCollector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setScorer(Scorable scorer) throws IOException {
  this.scorer = scorer;
  for (LeafFieldComparator comparator : leafComparators) {
    comparator.setScorer(scorer);
  }
}
 
Example 7
Source Project: lucene-solr   Source File: FirstPassGroupingCollector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setScorer(Scorable scorer) throws IOException {
  groupSelector.setScorer(scorer);
  for (LeafFieldComparator comparator : leafComparators) {
    comparator.setScorer(scorer);
  }
}
 
Example 8
@Override
public void setScorer(Scorable s) throws IOException {
  // Gathers all scorers, including s and "under":
  allScorers = new ArrayList<>();
  allScorers.add(s);
  int upto = 0;
  while(upto < allScorers.size()) {
    s = allScorers.get(upto++);
    for (Scorable.ChildScorable sub : s.getChildren()) {
      allScorers.add(sub.child);
    }
  }
}
 
Example 9
@Override
public void collect(int docID) {
  for(Scorable s : allScorers) {
    if (docID != s.docID()) {
      throw new IllegalStateException("subScorer=" + s + " has docID=" + s.docID() + " != collected docID=" + docID);
    }
  }
}
 
Example 10
Source Project: lucene-solr   Source File: DelegatingCollector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setScorer(Scorable scorer) throws IOException {
  this.scorer = scorer;
  if (leafDelegate != null) {
    leafDelegate.setScorer(scorer);
  }
}
 
Example 11
Source Project: incubator-pinot   Source File: LuceneDocIdCollector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public LeafCollector getLeafCollector(LeafReaderContext context) {
  return new LeafCollector() {

    @Override
    public void setScorer(Scorable scorer) throws IOException {
      // we don't use scoring, so this is NO-OP
    }

    @Override
    public void collect(int doc) throws IOException {
      _docIds.add(_docIdTranslator.getPinotDocId(doc));
    }
  };
}
 
Example 12
@Override
public LeafCollector getLeafCollector(LeafReaderContext context) {
  return new LeafCollector() {

    @Override
    public void setScorer(Scorable scorer) throws IOException {
      // we don't use scoring, so this is NO-OP
    }

    @Override
    public void collect(int doc) throws IOException {
      _docIds.add(doc);
    }
  };
}
 
Example 13
Source Project: crate   Source File: ProfileScorer.java    License: Apache License 2.0 5 votes vote down vote up
ProfileScorer(ProfileWeight w, Scorer scorer, QueryProfileBreakdown profile) throws IOException {
    super(w);
    this.scorer = scorer;
    this.profileWeight = w;
    scoreTimer = profile.getTimer(QueryTimingType.SCORE);
    nextDocTimer = profile.getTimer(QueryTimingType.NEXT_DOC);
    advanceTimer = profile.getTimer(QueryTimingType.ADVANCE);
    matchTimer = profile.getTimer(QueryTimingType.MATCH);
    shallowAdvanceTimer = profile.getTimer(QueryTimingType.SHALLOW_ADVANCE);
    computeMaxScoreTimer = profile.getTimer(QueryTimingType.COMPUTE_MAX_SCORE);
    ProfileScorer profileScorer = null;
    if (w.getQuery() instanceof ConstantScoreQuery && scorer instanceof ProfileScorer) {
        //Case when we have a totalHits query and it is not cached
        profileScorer = (ProfileScorer) scorer;
    } else if (w.getQuery() instanceof ConstantScoreQuery && scorer.getChildren().size() == 1) {
        //Case when we have a top N query. If the scorer has no children, it is because it is cached
        //and in that case we do not do any special treatment
        Scorable childScorer = scorer.getChildren().iterator().next().child;
        if (childScorer instanceof ProfileScorer) {
            profileScorer = (ProfileScorer) childScorer;
        }
    }
    if (profileScorer != null) {
        isConstantScoreQuery = true;
        profile.setTimer(QueryTimingType.NEXT_DOC, profileScorer.nextDocTimer);
        profile.setTimer(QueryTimingType.ADVANCE, profileScorer.advanceTimer);
        profile.setTimer(QueryTimingType.MATCH, profileScorer.matchTimer);
    } else {
        isConstantScoreQuery = false;
    }
}
 
Example 14
Source Project: crate   Source File: MinimumScoreCollector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setScorer(Scorable scorer) throws IOException {
    if (!(scorer instanceof ScoreCachingWrappingScorer)) {
        scorer = new ScoreCachingWrappingScorer(scorer);
    }
    this.scorer = scorer;
    leafCollector.setScorer(scorer);
}
 
Example 15
@Override
public void setScorer(Scorable scorer) {}
 
Example 16
Source Project: lucene-solr   Source File: Geo3DPointDistanceComparator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setScorer(Scorable scorer) {}
 
Example 17
Source Project: lucene-solr   Source File: DoubleRangeGroupSelector.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setScorer(Scorable scorer) throws IOException {
  this.values = source.getValues(context, DoubleValuesSource.fromScorer(scorer));
}
 
Example 18
Source Project: lucene-solr   Source File: AllGroupHeadsCollector.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected GroupHead<T> newGroupHead(int doc, T value, LeafReaderContext ctx, Scorable scorer) throws IOException {
  return new SortingGroupHead<>(sort, value, doc, ctx, scorer);
}
 
Example 19
Source Project: lucene-solr   Source File: AllGroupHeadsCollector.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void setScorer(Scorable scorer) throws IOException {
  for (LeafFieldComparator c : leafComparators) {
    c.setScorer(scorer);
  }
}
 
Example 20
Source Project: lucene-solr   Source File: AllGroupHeadsCollector.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected GroupHead<T> newGroupHead(int doc, T value, LeafReaderContext context, Scorable scorer) throws IOException {
  return new ScoringGroupHead<>(scorer, value, doc, context.docBase);
}
 
Example 21
Source Project: lucene-solr   Source File: AllGroupHeadsCollector.java    License: Apache License 2.0 4 votes vote down vote up
protected ScoringGroupHead(Scorable scorer, T groupValue, int doc, int docBase) throws IOException {
  super(groupValue, doc, docBase);
  assert scorer.docID() == doc;
  this.scorer = scorer;
  this.topScore = scorer.score();
}
 
Example 22
Source Project: lucene-solr   Source File: AllGroupHeadsCollector.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void setScorer(Scorable scorer) {
  this.scorer = scorer;
}
 
Example 23
Source Project: lucene-solr   Source File: TermGroupSelector.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setScorer(Scorable scorer) throws IOException { }
 
Example 24
Source Project: lucene-solr   Source File: LongRangeGroupSelector.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setScorer(Scorable scorer) throws IOException {
  this.values = source.getValues(context, DoubleValuesSource.fromScorer(scorer));
}
 
Example 25
Source Project: lucene-solr   Source File: GroupReducer.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Set the Scorer on all group collectors
 */
public final void setScorer(Scorable scorer) throws IOException {
  for (GroupCollector<C> collector : groups.values()) {
    collector.leafCollector.setScorer(scorer);
  }
}
 
Example 26
Source Project: lucene-solr   Source File: SecondPassGroupingCollector.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setScorer(Scorable scorer) throws IOException {
  groupSelector.setScorer(scorer);
  groupReducer.setScorer(scorer);
}
 
Example 27
Source Project: lucene-solr   Source File: AllGroupsCollector.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setScorer(Scorable scorer) throws IOException {}
 
Example 28
Source Project: lucene-solr   Source File: TopGroupsCollector.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setScorer(Scorable scorer) {
  this.scorer = scorer;
}
 
Example 29
Source Project: lucene-solr   Source File: ValueSourceGroupSelector.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setScorer(Scorable scorer) throws IOException { }
 
Example 30
Source Project: lucene-solr   Source File: GroupFacetCollector.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setScorer(Scorable scorer) throws IOException {
}