Java Code Examples for org.apache.lucene.search.Explanation#isMatch()

The following examples show how to use org.apache.lucene.search.Explanation#isMatch() . 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: FunctionScoreQuery.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
    Explanation subQueryExpl = subQueryWeight.explain(context, doc);
    if (!subQueryExpl.isMatch()) {
        return subQueryExpl;
    }
    Explanation expl;
    if (function != null) {
        Explanation functionExplanation = function.getLeafScoreFunction(context).explainScore(doc, subQueryExpl);
        expl = combineFunction.explain(subQueryExpl, functionExplanation, maxBoost);
    } else {
        expl = subQueryExpl;
    }
    if (minScore != null && minScore > expl.getValue()) {
        expl = Explanation.noMatch("Score value is too low, expected at least " + minScore + " but got " + expl.getValue(), expl);
    }
    return expl;
}
 
Example 2
Source File: ToParentBlockJoinQuery.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public Explanation explain(LeafReaderContext context, Weight childWeight) throws IOException {
  int prevParentDoc = parentBits.prevSetBit(parentApproximation.docID() - 1);
  int start = context.docBase + prevParentDoc + 1; // +1 b/c prevParentDoc is previous parent doc
  int end = context.docBase + parentApproximation.docID() - 1; // -1 b/c parentDoc is parent doc

  Explanation bestChild = null;
  int matches = 0;
  for (int childDoc = start; childDoc <= end; childDoc++) {
    Explanation child = childWeight.explain(context, childDoc - context.docBase);
    if (child.isMatch()) {
      matches++;
      if (bestChild == null || child.getValue().floatValue() > bestChild.getValue().floatValue()) {
        bestChild = child;
      }
    }
  }

  return Explanation.match(score(), String.format(Locale.ROOT,
      "Score based on %d child docs in range from %d to %d, best match:", matches, start, end), bestChild
  );
}
 
Example 3
Source File: QueryRescorer.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public Explanation explain(int topLevelDocId, SearchContext context, RescoreSearchContext rescoreContext,
                           Explanation sourceExplanation) throws IOException {
    QueryRescoreContext rescore = (QueryRescoreContext) rescoreContext;
    ContextIndexSearcher searcher = context.searcher();
    if (sourceExplanation == null) {
        // this should not happen but just in case
        return Explanation.noMatch("nothing matched");
    }
    // TODO: this isn't right?  I.e., we are incorrectly pretending all first pass hits were rescored?  If the requested docID was
    // beyond the top rescoreContext.window() in the first pass hits, we don't rescore it now?
    Explanation rescoreExplain = searcher.explain(rescore.query(), topLevelDocId);
    float primaryWeight = rescore.queryWeight();

    Explanation prim;
    if (sourceExplanation.isMatch()) {
        prim = Explanation.match(
                sourceExplanation.getValue() * primaryWeight,
                "product of:", sourceExplanation, Explanation.match(primaryWeight, "primaryWeight"));
    } else {
        prim = Explanation.noMatch("First pass did not match", sourceExplanation);
    }

    // NOTE: we don't use Lucene's Rescorer.explain because we want to insert our own description with which ScoreMode was used.  Maybe
    // we should add QueryRescorer.explainCombine to Lucene?
    if (rescoreExplain != null && rescoreExplain.isMatch()) {
        float secondaryWeight = rescore.rescoreQueryWeight();
        Explanation sec = Explanation.match(
                rescoreExplain.getValue() * secondaryWeight,
                "product of:",
                rescoreExplain, Explanation.match(secondaryWeight, "secondaryWeight"));
        ScoreMode scoreMode = rescore.scoreMode();
        return Explanation.match(
                scoreMode.combine(prim.getValue(), sec.getValue()),
                scoreMode + " of:",
                prim, sec);
    } else {
        return prim;
    }
}
 
Example 4
Source File: FunctionScoreQuery.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException {
  if (scoreExplanation.isMatch() == false) {
    return scoreExplanation;
  }
  Explanation boostExpl = boost.explain(ctx, docId, scoreExplanation);
  if (boostExpl.isMatch() == false) {
    return scoreExplanation;
  }
  return Explanation.match(scoreExplanation.getValue().doubleValue() * boostExpl.getValue().doubleValue(),
      "product of:", scoreExplanation, boostExpl);
}
 
Example 5
Source File: FunctionScoreQuery.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException {
  Explanation inner = query.explain(ctx, docId, scoreExplanation);
  if (inner.isMatch() == false) {
    return inner;
  }
  return Explanation.match(boost, "Matched boosting query " + query.toString());
}
 
Example 6
Source File: LatLonType.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public Explanation explain(Explanation base, int doc) throws IOException {
  if (base.isMatch() == false) {
    return base;
  }
  double dist = dist(latVals.doubleVal(doc), lonVals.doubleVal(doc));

  String description = SpatialDistanceQuery.this.toString();
  return Explanation.match((float) (base.getValue().floatValue() * dist), description + " product of:",
      base, Explanation.match((float) dist, "hsin("+latVals.doubleVal(doc)+","+lonVals.doubleVal(doc)));
}