You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2015/02/25 15:10:39 UTC

svn commit: r1662218 - in /lucene/dev/trunk/lucene/core/src: java/org/apache/lucene/search/BooleanWeight.java test/org/apache/lucene/search/TestSimpleExplanations.java

Author: jpountz
Date: Wed Feb 25 14:10:38 2015
New Revision: 1662218

URL: http://svn.apache.org/r1662218
Log:
LUCENE-6227: Fix explanations of FILTER clauses.

Modified:
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestSimpleExplanations.java

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java?rev=1662218&r1=1662217&r2=1662218&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java Wed Feb 25 14:10:38 2015
@@ -110,6 +110,7 @@ public class BooleanWeight extends Weigh
     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 Weigh
           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 Weigh
           sumExpl.addDetail(r);
           fail = true;
         }
+        if (!c.isProhibited()) {
+          matchCount++;
+        }
         if (c.getOccur() == Occur.SHOULD) {
           shouldMatchCount++;
         }
@@ -165,7 +169,7 @@ public class BooleanWeight extends Weigh
       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);

Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestSimpleExplanations.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestSimpleExplanations.java?rev=1662218&r1=1662217&r2=1662218&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestSimpleExplanations.java (original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestSimpleExplanations.java Wed Feb 25 14:10:38 2015
@@ -483,6 +483,34 @@ public class TestSimpleExplanations exte
     
   }
 
+  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 {