// TODO: Add root node in the explanation
@Override
public Explanation explain(final AtomicReaderContext context, final int doc)
throws IOException {
final ComplexExplanation sumExpl = new ComplexExplanation();
sumExpl.setDescription("sum of:");
int coord = 0;
float sum = 0.0f;
boolean fail = false;
final Iterator<NodeBooleanClause> cIter = clauses.iterator();
for (final Weight w : weights) {
final NodeBooleanClause c = cIter.next();
if (w.scorer(context, true, true, context.reader().getLiveDocs()) == null) {
if (c.isRequired()) {
fail = true;
final Explanation r = new Explanation(0.0f, "no match on required " +
"clause (" + c.getQuery().toString() + ")");
sumExpl.addDetail(r);
}
continue;
}
final Explanation e = w.explain(context, doc);
if (e.isMatch()) {
if (!c.isProhibited()) {
sumExpl.addDetail(e);
sum += e.getValue();
coord++;
}
else {
final Explanation r =
new Explanation(0.0f, "match on prohibited clause (" +
c.getQuery().toString() + ")");
r.addDetail(e);
sumExpl.addDetail(r);
fail = true;
}
}
else if (c.isRequired()) {
final Explanation r = new Explanation(0.0f, "no match on required " +
"clause (" + c.getQuery().toString() + ")");
r.addDetail(e);
sumExpl.addDetail(r);
fail = true;
}
}
if (fail) {
sumExpl.setMatch(Boolean.FALSE);
sumExpl.setValue(0.0f);
sumExpl.setDescription
("Failure to meet condition(s) of required/prohibited clause(s)");
return sumExpl;
}
sumExpl.setMatch(0 < coord ? Boolean.TRUE : Boolean.FALSE);
sumExpl.setValue(sum);
return sumExpl;
}