mirror of https://github.com/apache/lucene.git
LUCENE-6227: Fix explanations of FILTER clauses.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1662218 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6ae36bc6e9
commit
dfd94b518a
|
@ -110,6 +110,7 @@ public class BooleanWeight extends Weight {
|
|||
int coord = 0;
|
||||
float sum = 0.0f;
|
||||
boolean fail = false;
|
||||
int matchCount = 0;
|
||||
int shouldMatchCount = 0;
|
||||
Iterator<BooleanClause> cIter = query.clauses().iterator();
|
||||
for (Iterator<Weight> wIter = weights.iterator(); wIter.hasNext();) {
|
||||
|
@ -130,10 +131,10 @@ public class BooleanWeight extends Weight {
|
|||
sum += e.getValue();
|
||||
coord++;
|
||||
} else if (c.isRequired()) {
|
||||
Explanation r =
|
||||
new Explanation(0.0f, "match on required clause (" + c.getQuery().toString() + ")");
|
||||
r.addDetail(e);
|
||||
sumExpl.addDetail(r);
|
||||
Explanation r = new Explanation(0f, "match on required clause, product of:");
|
||||
r.addDetail(new Explanation(0f, Occur.FILTER + " clause"));
|
||||
r.addDetail(e);
|
||||
sumExpl.addDetail(r);
|
||||
} else if (c.isProhibited()) {
|
||||
Explanation r =
|
||||
new Explanation(0.0f, "match on prohibited clause (" + c.getQuery().toString() + ")");
|
||||
|
@ -141,6 +142,9 @@ public class BooleanWeight extends Weight {
|
|||
sumExpl.addDetail(r);
|
||||
fail = true;
|
||||
}
|
||||
if (!c.isProhibited()) {
|
||||
matchCount++;
|
||||
}
|
||||
if (c.getOccur() == Occur.SHOULD) {
|
||||
shouldMatchCount++;
|
||||
}
|
||||
|
@ -165,7 +169,7 @@ public class BooleanWeight extends Weight {
|
|||
return sumExpl;
|
||||
}
|
||||
|
||||
sumExpl.setMatch(0 < coord ? Boolean.TRUE : Boolean.FALSE);
|
||||
sumExpl.setMatch(0 < matchCount);
|
||||
sumExpl.setValue(sum);
|
||||
|
||||
final float coordFactor = disableCoord ? 1.0f : coord(coord, maxCoord);
|
||||
|
|
|
@ -483,6 +483,34 @@ public class TestSimpleExplanations extends BaseExplanationTestCase {
|
|||
|
||||
}
|
||||
|
||||
public void testBQ23() throws Exception {
|
||||
BooleanQuery query = new BooleanQuery();
|
||||
query.add(new TermQuery(new Term(FIELD, "w1")), BooleanClause.Occur.FILTER);
|
||||
query.add(new TermQuery(new Term(FIELD, "w2")), BooleanClause.Occur.FILTER);
|
||||
qtest(query, new int[] { 0,1,2,3 });
|
||||
}
|
||||
|
||||
public void testBQ24() throws Exception {
|
||||
BooleanQuery query = new BooleanQuery();
|
||||
query.add(new TermQuery(new Term(FIELD, "w1")), BooleanClause.Occur.FILTER);
|
||||
query.add(new TermQuery(new Term(FIELD, "w2")), BooleanClause.Occur.SHOULD);
|
||||
qtest(query, new int[] { 0,1,2,3 });
|
||||
}
|
||||
|
||||
public void testBQ25() throws Exception {
|
||||
BooleanQuery query = new BooleanQuery();
|
||||
query.add(new TermQuery(new Term(FIELD, "w1")), BooleanClause.Occur.FILTER);
|
||||
query.add(new TermQuery(new Term(FIELD, "w2")), BooleanClause.Occur.MUST);
|
||||
qtest(query, new int[] { 0,1,2,3 });
|
||||
}
|
||||
|
||||
public void testBQ26() throws Exception {
|
||||
BooleanQuery query = new BooleanQuery();
|
||||
query.add(new TermQuery(new Term(FIELD, "w1")), BooleanClause.Occur.FILTER);
|
||||
query.add(new TermQuery(new Term(FIELD, "xx")), BooleanClause.Occur.MUST_NOT);
|
||||
qtest(query, new int[] { 0,1 });
|
||||
}
|
||||
|
||||
/* BQ of TQ: using alt so some fields have zero boost and some don't */
|
||||
|
||||
public void testMultiFieldBQ1() throws Exception {
|
||||
|
|
Loading…
Reference in New Issue