org.apache.lucene.search.Scorable Java Examples

The following examples show how to use org.apache.lucene.search.Scorable. 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: ScoringMatch.java    From lucene-solr with 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 File: ExportQParserPlugin.java    From lucene-solr with 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 File: RankQueryTestPlugin.java    From lucene-solr with 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 File: RealtimeLuceneDocIdCollector.java    From incubator-pinot with 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(doc);
    }
  };
}
 
Example #5
Source File: AssertingSubDocsAtOnceCollector.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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 #6
Source File: DelegatingCollector.java    From lucene-solr with 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 #7
Source File: AssertingSubDocsAtOnceCollector.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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 #8
Source File: FirstPassGroupingCollector.java    From lucene-solr with 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 #9
Source File: BlockGroupingCollector.java    From lucene-solr with 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 #10
Source File: LuceneDocIdCollector.java    From incubator-pinot with 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 #11
Source File: ProfileScorer.java    From crate with 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 #12
Source File: MinimumScoreCollector.java    From crate with 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 #13
Source File: AllGroupHeadsCollector.java    From lucene-solr with 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 #14
Source File: AllGroupHeadsCollector.java    From lucene-solr with 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 #15
Source File: MaxScoreCollector.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void setScorer(Scorable scorer) {
  this.scorer = scorer;
}
 
Example #16
Source File: ScoreCollectorExpression.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public void setScorer(Scorable scorer) {
    this.scorer = scorer;
}
 
Example #17
Source File: LuceneReferenceResolver.java    From crate with Apache License 2.0 4 votes vote down vote up
public void setScorer(final Scorable scorer) {
    inner.setScorer(scorer);
}
 
Example #18
Source File: ReservoirSampler.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public void setScorer(Scorable scorer) {
}
 
Example #19
Source File: LuceneOrderedDocCollector.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public void setScorer(Scorable scorer) throws IOException {
    raiseIfKilled.run();
    delegate.setScorer(scorer);
}
 
Example #20
Source File: NullFieldComparatorSource.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public void setScorer(Scorable scorer) {
}
 
Example #21
Source File: InputFieldComparator.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public void setScorer(Scorable scorer) {
}
 
Example #22
Source File: HashQParserPlugin.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public void setScorer(Scorable scorer) throws IOException{
  leafCollector.setScorer(scorer);
}
 
Example #23
Source File: CollapsingQParserPlugin.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void setScorer(Scorable s) throws IOException {
  super.setScorer(s);
  this.compareState.setScorer(s);
}
 
Example #24
Source File: CollapsingQParserPlugin.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public void setScorer(Scorable scorer) throws IOException {
  this.scorer = scorer;
}
 
Example #25
Source File: CollapsingQParserPlugin.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void setScorer(Scorable scorer) throws IOException {
  this.collapseStrategy.setScorer(scorer);
}
 
Example #26
Source File: CollapsingQParserPlugin.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public void setScorer(Scorable scorer) throws IOException {
  this.collapseStrategy.setScorer(scorer);
}
 
Example #27
Source File: LatLonPointDistanceComparator.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void setScorer(Scorable scorer) {}
 
Example #28
Source File: XYPointDistanceComparator.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void setScorer(Scorable scorer) {}
 
Example #29
Source File: BooleanQueryTst.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void setScorer(Scorable scorer) throws IOException {
  this.scorer = scorer;
}
 
Example #30
Source File: QueryMatch.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
protected QueryMatch doMatch(String queryId, int doc, Scorable scorer) {
  return new QueryMatch(queryId);
}