@Override public final Explanation explain(BasicStats stats) { return Explanation.match( lambda(stats), getClass().getSimpleName() + ", computed from: ", Explanation.match(stats.getDocFreq(), "docFreq"), Explanation.match(stats.getNumberOfDocuments(), "numberOfDocuments")); }
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { Explanation expl = subQueryWeight.explain(context, doc); if (!expl.isMatch()) { return expl; } // First: Gather explanations for all filters List<Explanation> filterExplanations = new ArrayList<>(); for (int i = 0; i < filterFunctions.length; ++i) { Bits docSet = Lucene.asSequentialAccessBits( context.reader().maxDoc(), filterWeights[i].scorer(context)); if (docSet.get(doc)) { FilterFunction filterFunction = filterFunctions[i]; Explanation functionExplanation = filterFunction.function.getLeafScoreFunction(context).explainScore(doc, expl); double factor = functionExplanation.getValue(); float sc = CombineFunction.toFloat(factor); Explanation filterExplanation = Explanation.match( sc, "function score, product of:", Explanation.match(1.0f, "match filter: " + filterFunction.filter.toString()), functionExplanation); filterExplanations.add(filterExplanation); } } if (filterExplanations.size() > 0) { FiltersFunctionFactorScorer scorer = functionScorer(context); int actualDoc = scorer.iterator().advance(doc); assert (actualDoc == doc); double score = scorer.computeScore(doc, expl.getValue()); Explanation factorExplanation = Explanation.match( CombineFunction.toFloat(score), "function score, score mode [" + scoreMode.toString().toLowerCase(Locale.ROOT) + "]", filterExplanations); expl = combineFunction.explain(expl, factorExplanation, maxBoost); } 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; }
public Explanation explain(int docBase) throws IOException { int start = docBase + prevParentDoc + 1; // +1 b/c prevParentDoc is previous parent doc int end = docBase + parentDoc - 1; // -1 b/c parentDoc is parent doc return Explanation.match( score(), String.format(Locale.ROOT, "Score based on child doc range from %d to %d", start, end)); }
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { SortedDocValues values = DocValues.getSorted(context.reader(), joinField); if (values != null) { int segmentOrd = values.getOrd(doc); if (segmentOrd != -1) { BytesRef joinValue = values.lookupOrd(segmentOrd); return Explanation.match( queryNorm, "Score based on join value " + joinValue.utf8ToString()); } } return Explanation.noMatch("Not a match"); }
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { SortedDocValues values = DocValues.getSorted(context.reader(), joinField); if (values != null) { int segmentOrd = values.getOrd(doc); if (segmentOrd != -1) { final float score; if (globalOrds != null) { long globalOrd = globalOrds.getGlobalOrds(context.ord).get(segmentOrd); score = collector.score((int) globalOrd); } else { score = collector.score(segmentOrd); } BytesRef joinValue = values.lookupOrd(segmentOrd); return Explanation.match(score, "Score based on join value " + joinValue.utf8ToString()); } } return Explanation.noMatch("Not a match"); }
/** * Explains the score. Returns the name of the model only, since both {@code tfn} and {@code * lambda} are explained elsewhere. */ public Explanation explain(BasicStats stats, float tfn, float lambda) { return Explanation.match(score(stats, tfn, lambda), getClass().getSimpleName()); }
@Override public Explanation explainFunction(String valueExpl, double value, double scale) { return Explanation.match( (float) evaluate(value, scale), "exp(- " + valueExpl + " * " + -1 * scale + ")"); }
@Override public Explanation explainFunction(String distanceString, double distanceVal, double scale) { return Explanation.match((float) distanceVal, "" + distanceVal); }