Refine search
/** 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"); } }
/** * Create a new explanation for a match. * @param value the contribution to the score of the document * @param description how {@code value} was computed * @param details sub explanations that contributed to this explanation */ public static Explanation match(float value, String description, Collection<Explanation> details) { return new Explanation(true, value, description, details); }
/** Render an explanation as text. */ @Override public String toString() { return toString(0); }
private String getSummary() { return getValue() + " = " + getDescription(); }
private Explanation explainScore(int doc, Explanation freq, IDFStats stats, NumericDocValues norms, float[] normTable) throws IOException { Explanation queryExpl = Explanation.match(stats.boost, "boost"); Explanation fieldExpl = explainField(doc, freq, stats, norms, normTable); if (stats.boost == 1f) { return fieldExpl; } return Explanation.match( queryExpl.getValue() * fieldExpl.getValue(), "score(doc="+doc+",freq="+freq.getValue()+"), product of:", queryExpl, fieldExpl); } }
private String toString(int depth) { StringBuilder buffer = new StringBuilder(); for (int i = 0; i < depth; i++) { buffer.append(" "); } buffer.append(getSummary()); buffer.append("\n"); Explanation[] details = getDetails(); for (int i = 0 ; i < details.length; i++) { buffer.append(details[i].toString(depth+1)); } return buffer.toString(); }
public static void writeExplanation(StreamOutput out, Explanation explanation) throws IOException { out.writeBoolean(explanation.isMatch()); out.writeString(explanation.getDescription()); Explanation[] subExplanations = explanation.getDetails(); out.writeVInt(subExplanations.length); for (Explanation subExp : subExplanations) { writeExplanation(out, subExp); } if (explanation.isMatch()) { out.writeFloat(explanation.getValue()); } }
@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(LeafReaderContext context, int doc) throws IOException { Scorer scorer = inner.scorer(context); if (scorer.iterator().advance(doc) != doc) return Explanation.noMatch("No match"); Explanation scoreExplanation = inner.explain(context, doc); Explanation expl = valueSource.explain(context, doc, scoreExplanation); return Explanation.match(expl.getValue() * boost, "product of:", Explanation.match(boost, "boost"), expl); }
@Override public Explanation explain(int doc) { Explanation exp = super.explain(doc); List<Explanation> details = new ArrayList<>(Arrays.asList(exp.getDetails())); details.add(shapeValues.explain(doc)); return Explanation.match(exp.getValue(), exp.getDescription(), details); } };
private void buildExplanation(XContentBuilder builder, Explanation explanation) throws IOException { builder.startObject(); builder.field(Fields.VALUE, explanation.getValue()); builder.field(Fields.DESCRIPTION, explanation.getDescription()); Explanation[] innerExps = explanation.getDetails(); if (innerExps != null) { builder.startArray(Fields.DETAILS); for (Explanation exp : innerExps) { buildExplanation(builder, exp); } builder.endArray(); } builder.endObject(); }
@Override public Explanation explain(AtomicReaderContext context, int doc) throws IOException { // explain query weight Explanation queryExpl = new ComplexExplanation(true, queryWeight, "MatchNoneDocsQuery, product of:"); if (getBoost() != 1.0f) { queryExpl.addDetail(new Explanation(getBoost(), "boost")); } queryExpl.addDetail(new Explanation(queryNorm, "queryNorm")); return queryExpl; }
public Explanation explain(int doc) throws IOException { Explanation subQueryExpl = weight.qWeight.explain(reader,doc); if (!subQueryExpl.isMatch()) { return subQueryExpl; } float sc = subQueryExpl.getValue() * vals.floatVal(doc); Explanation res = new ComplexExplanation( true, sc, BoostedQuery.this.toString() + ", product of:"); res.addDetail(subQueryExpl); res.addDetail(vals.explain(doc)); return res; } }
/** Explain the score of a document. * @todo Also show the total score. * See BooleanScorer.explain() on how to do this. */ public Explanation explain(int doc) throws IOException { Explanation res = new Explanation(); res.setDescription("required, optional"); res.addDetail(reqScorer.explain(doc)); res.addDetail(optScorer.explain(doc)); return res; } }
@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() * boostExpl.getValue(), "product of:", scoreExplanation, boostExpl); }
@Override public Explanation explain(int docID, Explanation freq) throws IOException { doc.docID = docID; float score = score(docID, freq.getValue()); return Explanation.match(score, "score from " + ScriptedSimilarity.this.toString() + " computed from:", Explanation.match((float) scoreWeight, "weight"), Explanation.match(weight.query.boost, "query.boost"), Explanation.match(weight.field.docCount, "field.docCount"), Explanation.match(weight.field.sumDocFreq, "field.sumDocFreq"), Explanation.match(weight.field.sumTotalTermFreq, "field.sumTotalTermFreq"), Explanation.match(term.docFreq, "term.docFreq"), Explanation.match(term.totalTermFreq, "term.totalTermFreq"), Explanation.match(freq.getValue(), "doc.freq", freq.getDetails()), Explanation.match(doc.getLength(), "doc.length")); } };
@Override public Explanation customExplain( final int doc, final Explanation subQueryExplanation, final Explanation[] valSrcExplanations) throws IOException { float bonus = subQueryExplanation.getValue() > 0 ? (this.bits.get(doc) ? this.bonus : 0) : subQueryExplanation.getValue(); Explanation result = new Explanation( subQueryExplanation.getValue() + bonus, "bonus = " + bonus); result.addDetail(subQueryExplanation); return result; }
@Override Explanation explain(String field, String feature, float w, int doc, int freq) throws IOException { float featureValue = decodeFeatureValue(freq); float score = scorer(field, w).score(doc, freq); return Explanation.match(score, "Log function on the " + field + " field for the " + feature + " feature, computed as w * log(a + S) from:", Explanation.match(w, "w, weight of this function"), Explanation.match(scalingFactor, "a, scaling factor"), Explanation.match(featureValue, "S, feature value")); } }
@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()); }
/** 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); }