@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { return Explanation.noMatch(reason); }
/** Explain the score we computed for doc */ @Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { boolean match = false; float max = Float.NEGATIVE_INFINITY, sum = 0.0f; List<Explanation> subs = new ArrayList<>(); for (Weight wt : weights) { Explanation e = wt.explain(context, doc); if (e.isMatch()) { match = true; subs.add(e); sum += e.getValue(); max = Math.max(max, e.getValue()); } } if (match) { final float score = max + (sum - max) * tieBreakerMultiplier; final String desc = tieBreakerMultiplier == 0.0f ? "max of:" : "max plus " + tieBreakerMultiplier + " times others of:"; return Explanation.match(score, desc, subs); } else { return Explanation.noMatch("No matching clause"); } }
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { String desc = "weight(" + getQuery() + " in " + doc + ") [" + function + "]"; Terms terms = context.reader().terms(fieldName); if (terms == null) { return Explanation.noMatch(desc + ". Field " + fieldName + " doesn't exist."); } TermsEnum termsEnum = terms.iterator(); if (termsEnum.seekExact(new BytesRef(featureName)) == false) { return Explanation.noMatch(desc + ". Feature " + featureName + " doesn't exist."); } PostingsEnum postings = termsEnum.postings(null, PostingsEnum.FREQS); if (postings.advance(doc) != doc) { return Explanation.noMatch(desc + ". Feature " + featureName + " isn't set."); } return function.explain(fieldName, featureName, boost, doc, postings.freq()); }
Explanation.match(0f, Occur.FILTER + " clause"), e)); } else if (c.isProhibited()) { subs.add(Explanation.noMatch("match on prohibited clause (" + c.getQuery().toString() + ")", e)); fail = true; subs.add(Explanation.noMatch("no match on required clause (" + c.getQuery().toString() + ")", e)); fail = true; return Explanation.noMatch("Failure to meet condition(s) of required/prohibited clause(s)", subs); } else if (matchCount == 0) { return Explanation.noMatch("No matching clauses", subs); } else if (shouldMatchCount < minShouldMatch) { return Explanation.noMatch("Failure to match minimum number of optional clauses: " + minShouldMatch, subs); } else {
/** Expert: low-level implementation method * Returns an Explanation that describes how <code>doc</code> scored against * <code>weight</code>. * * <p>This is intended to be used in developing Similarity implementations, * and, for good performance, should not be displayed with every hit. * Computing an explanation is as expensive as executing the query over the * entire index. * <p>Applications should call {@link IndexSearcher#explain(Query, int)}. * @throws BooleanQuery.TooManyClauses If a query would exceed * {@link BooleanQuery#getMaxClauseCount()} clauses. */ protected Explanation explain(Weight weight, int doc) throws IOException { int n = ReaderUtil.subIndex(doc, leafContexts); final LeafReaderContext ctx = leafContexts.get(n); int deBasedDoc = doc - ctx.docBase; final Bits liveDocs = ctx.reader().getLiveDocs(); if (liveDocs != null && liveDocs.get(deBasedDoc) == false) { return Explanation.noMatch("Document " + doc + " is deleted"); } return weight.explain(ctx, deBasedDoc); }
@Override public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException { DoubleValues values = getValues(ctx, null); if (values.advanceExact(docId)) return Explanation.match((float) values.doubleValue(), this.toString()); else return Explanation.noMatch(this.toString()); }
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { PhraseMatcher matcher = getPhraseMatcher(context, false); if (matcher == null || matcher.approximation.advance(doc) != doc) { return Explanation.noMatch("no matching terms"); } matcher.reset(); if (matcher.nextMatch() == false) { return Explanation.noMatch("no matching phrase"); } Similarity.SimScorer simScorer = similarity.simScorer(stats, context); float freq = matcher.sloppyWeight(simScorer); while (matcher.nextMatch()) { freq += matcher.sloppyWeight(simScorer); } Explanation freqExplanation = Explanation.match(freq, "phraseFreq=" + freq); Explanation scoreExplanation = simScorer.explain(doc, freqExplanation); return Explanation.match( scoreExplanation.getValue(), "weight("+getQuery()+" in "+doc+") [" + similarity.getClass().getSimpleName() + "], result of:", scoreExplanation); }
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { SpanScorer scorer = scorer(context); if (scorer != null) { int newDoc = scorer.iterator().advance(doc); if (newDoc == doc) { float freq = scorer.sloppyFreq(); SimScorer docScorer = similarity.simScorer(simWeight, context); Explanation freqExplanation = Explanation.match(freq, "phraseFreq=" + freq); Explanation scoreExplanation = docScorer.explain(doc, freqExplanation); return Explanation.match(scoreExplanation.getValue(), "weight("+getQuery()+" in "+doc+") [" + similarity.getClass().getSimpleName() + "], result of:", scoreExplanation); } } return Explanation.noMatch("no matching term"); }
@Override public Explanation explain(IndexSearcher searcher, Explanation firstPassExplanation, int docID) throws IOException { Explanation secondPassExplanation = searcher.explain(query, docID); Float secondPassScore = secondPassExplanation.isMatch() ? secondPassExplanation.getValue() : null; float score; if (secondPassScore == null) { score = combine(firstPassExplanation.getValue(), false, 0.0f); } else { score = combine(firstPassExplanation.getValue(), true, secondPassScore.floatValue()); } Explanation first = Explanation.match(firstPassExplanation.getValue(), "first pass score", firstPassExplanation); Explanation second; if (secondPassScore == null) { second = Explanation.noMatch("no second pass score"); } else { second = Explanation.match(secondPassScore, "second pass score", secondPassExplanation); } return Explanation.match(score, "combined first and second pass score using " + getClass(), first, second); }
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { TermScorer scorer = (TermScorer) scorer(context); if (scorer != null) { int newDoc = scorer.iterator().advance(doc); if (newDoc == doc) { float freq = scorer.freq(); SimScorer docScorer = similarity.simScorer(stats, context); Explanation freqExplanation = Explanation.match(freq, "termFreq=" + freq); Explanation scoreExplanation = docScorer.explain(doc, freqExplanation); return Explanation.match( scoreExplanation.getValue(), "weight(" + getQuery() + " in " + doc + ") [" + similarity.getClass().getSimpleName() + "], result of:", scoreExplanation); } } return Explanation.noMatch("no matching term"); } }
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { Scorer scorer = scorer(context); if (scorer != null) { int newDoc = scorer.iterator().advance(doc); if (newDoc == doc) { final float freq; if (scorer instanceof SynonymScorer) { SynonymScorer synScorer = (SynonymScorer) scorer; freq = synScorer.tf(synScorer.getSubMatches()); } else { assert scorer instanceof TermScorer; freq = ((TermScorer)scorer).freq(); } SimScorer docScorer = similarity.simScorer(simWeight, context); Explanation freqExplanation = Explanation.match(freq, "termFreq=" + freq); Explanation scoreExplanation = docScorer.explain(doc, freqExplanation); return Explanation.match( scoreExplanation.getValue(), "weight(" + getQuery() + " in " + doc + ") [" + similarity.getClass().getSimpleName() + "], result of:", scoreExplanation); } } return Explanation.noMatch("no matching term"); }
/** * An explanation of the value for the named document. * * @param ctx the readers context to create the {@link Explanation} for. * @param docId the document's id relative to the given context's reader * @return an Explanation for the value * @throws IOException if an {@link IOException} occurs */ public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException { DoubleValues dv = getValues(ctx, DoubleValuesSource.constant(scoreExplanation.getValue()).getValues(ctx, null)); if (dv.advanceExact(docId)) return Explanation.match((float) dv.doubleValue(), this.toString()); return Explanation.noMatch(this.toString()); }
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { final Scorer s = scorer(context); final boolean exists; if (s == null) { exists = false; } else { final TwoPhaseIterator twoPhase = s.twoPhaseIterator(); if (twoPhase == null) { exists = s.iterator().advance(doc) == doc; } else { exists = twoPhase.approximation().advance(doc) == doc && twoPhase.matches(); } } if (exists) { return Explanation.match( score, getQuery().toString() + (score == 1f ? "" : "^" + score)); } else { return Explanation.noMatch(getQuery().toString() + " doesn't match id " + doc); } }
public static Explanation readExplanation(StreamInput in) throws IOException { boolean match = in.readBoolean(); String description = in.readString(); final Explanation[] subExplanations = new Explanation[in.readVInt()]; for (int i = 0; i < subExplanations.length; ++i) { subExplanations[i] = readExplanation(in); } if (match) { return Explanation.match(in.readFloat(), description, subExplanations); } else { return Explanation.noMatch(description, subExplanations); } }
@Override public Explanation explainScore(int docId, Explanation subQueryScore) throws IOException { if (distance.advanceExact(docId) == false) { return Explanation.noMatch("No value for the distance"); } double value = distance.doubleValue(); return Explanation.match( (float) score(docId, subQueryScore.getValue()), "Function for field " + getFieldName() + ":", func.explainFunction(getDistanceString(ctx, docId), value, scale)); } };
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { AllTermScorer scorer = scorer(context); if (scorer != null) { int newDoc = scorer.iterator().advance(doc); if (newDoc == doc) { float score = scorer.score(); float freq = scorer.freq(); SimScorer docScorer = similarity.simScorer(stats, context); Explanation freqExplanation = Explanation.match(freq, "termFreq=" + freq); Explanation termScoreExplanation = docScorer.explain(doc, freqExplanation); Explanation payloadBoostExplanation = Explanation.match(scorer.payloadBoost(), "payloadBoost=" + scorer.payloadBoost()); return Explanation.match( score, "weight(" + getQuery() + " in " + doc + ") [" + similarity.getClass().getSimpleName() + "], product of:", termScoreExplanation, payloadBoostExplanation); } } return Explanation.noMatch("no matching term"); }
expl = Explanation.noMatch("Score value is too low, expected at least " + minScore + " but got " + expl.getValue(), expl);
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { Explanation explain = doExplain(context, doc); return explain == null ? Explanation.noMatch("no matching docs") : explain; }
@Override public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException { if (fv.advanceExact(docId)) return Explanation.match((float)fv.doubleValue(), "ReplaceableConstDoubleValues"); else return Explanation.noMatch("ReplaceableConstDoubleValues"); }