You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "slow-J (via GitHub)" <gi...@apache.org> on 2026/06/09 16:17:57 UTC

[PR] BooleanWeight.explain prints failing optional clauses [lucene]

slow-J opened a new pull request, #16229:
URL: https://github.com/apache/lucene/pull/16229

   When a BooleanQuery fails to match because either `shouldMatchCount < minShouldMatch` or nothing matched in the disjunction: the explanation now includes `no match on optional clause (…)` sub-explanations for each non-matching SHOULD clause.
   
   Previously, BooleanWeight.explain silently discarded non-matching SHOULDs. The explanation would say "Failure to match minimum number of optional clauses: X" without stating the clauses which failed to match.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] BooleanWeight.explain prints failing optional clauses (when required) [lucene]

Posted by "javanna (via GitHub)" <gi...@apache.org>.
javanna commented on PR #16229:
URL: https://github.com/apache/lucene/pull/16229#issuecomment-4707772524

   Heads up that I backported this change, given the changes entry was under 10.5 and the milestone indicated also 10.5. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] BooleanWeight.explain prints failing optional clauses (when required) [lucene]

Posted by "epotyom (via GitHub)" <gi...@apache.org>.
epotyom commented on code in PR #16229:
URL: https://github.com/apache/lucene/pull/16229#discussion_r3387700826


##########
lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java:
##########
@@ -1411,4 +1411,49 @@ public void testClauseSetsImmutability() throws Exception {
         UnsupportedOperationException.class,
         () -> bq.clauses().add(new BooleanClause(MatchNoDocsQuery.INSTANCE, Occur.SHOULD)));
   }
+
+  public void testExplainFailingOptionalClauses() throws Exception {

Review Comment:
   I think explanation tests usually live under BaseExplanationTestCase subclasses - do you think we can add tests to one of them?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] BooleanWeight.explain prints failing optional clauses (when required) [lucene]

Posted by "slow-J (via GitHub)" <gi...@apache.org>.
slow-J commented on code in PR #16229:
URL: https://github.com/apache/lucene/pull/16229#discussion_r3387979115


##########
lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java:
##########
@@ -1411,4 +1411,49 @@ public void testClauseSetsImmutability() throws Exception {
         UnsupportedOperationException.class,
         () -> bq.clauses().add(new BooleanClause(MatchNoDocsQuery.INSTANCE, Occur.SHOULD)));
   }
+
+  public void testExplainFailingOptionalClauses() throws Exception {

Review Comment:
   Thanks for the feedback @epotyom, I'll move the test there.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] BooleanWeight.explain prints failing optional clauses (when required) [lucene]

Posted by "msokolov (via GitHub)" <gi...@apache.org>.
msokolov commented on code in PR #16229:
URL: https://github.com/apache/lucene/pull/16229#discussion_r3390459036


##########
lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java:
##########
@@ -97,14 +98,19 @@ public Explanation explain(LeafReaderContext context, int doc) throws IOExceptio
         subs.add(
             Explanation.noMatch("no match on required clause (" + c.query().toString() + ")", e));
         fail = true;
+      } else if (c.occur() == Occur.SHOULD) {
+        failingOptionals.add(
+            Explanation.noMatch("no match on optional clause (" + c.query().toString() + ")", e));
       }
     }
     if (fail) {
       return Explanation.noMatch(
           "Failure to meet condition(s) of required/prohibited clause(s)", subs);
     } else if (matchCount == 0) {
+      subs.addAll(failingOptionals);
       return Explanation.noMatch("No matching clauses", subs);
     } else if (shouldMatchCount < minShouldMatch) {
+      subs.addAll(failingOptionals);

Review Comment:
   I wonder if in this case we should include all of the optional clauses, and not merely the failing ones?  Otherwise it's hard to tell how many of the failing clauses would have had to match in order for the entire query to match.  Maybe we could just add a count to the description, like "Failure to match min ... <mincount>, only <count> matched".



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] BooleanWeight.explain prints failing optional clauses (when required) [lucene]

Posted by "iprithv (via GitHub)" <gi...@apache.org>.
iprithv commented on PR #16229:
URL: https://github.com/apache/lucene/pull/16229#issuecomment-4662114401

   thank you @slow-J, can you add test for this?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] BooleanWeight.explain prints failing optional clauses (when required) [lucene]

Posted by "slow-J (via GitHub)" <gi...@apache.org>.
slow-J commented on PR #16229:
URL: https://github.com/apache/lucene/pull/16229#issuecomment-4662333007

   Thanks @iprithv ! Good point, looking at adding some tests now.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] BooleanWeight.explain prints failing optional clauses (when required) [lucene]

Posted by "slow-J (via GitHub)" <gi...@apache.org>.
slow-J commented on code in PR #16229:
URL: https://github.com/apache/lucene/pull/16229#discussion_r3394997782


##########
lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java:
##########
@@ -97,14 +98,19 @@ public Explanation explain(LeafReaderContext context, int doc) throws IOExceptio
         subs.add(
             Explanation.noMatch("no match on required clause (" + c.query().toString() + ")", e));
         fail = true;
+      } else if (c.occur() == Occur.SHOULD) {
+        failingOptionals.add(
+            Explanation.noMatch("no match on optional clause (" + c.query().toString() + ")", e));
       }
     }
     if (fail) {
       return Explanation.noMatch(
           "Failure to meet condition(s) of required/prohibited clause(s)", subs);
     } else if (matchCount == 0) {
+      subs.addAll(failingOptionals);
       return Explanation.noMatch("No matching clauses", subs);
     } else if (shouldMatchCount < minShouldMatch) {
+      subs.addAll(failingOptionals);

Review Comment:
   Thanks Mike, I'll look into adding a count here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] BooleanWeight.explain prints failing optional clauses (when required) [lucene]

Posted by "msokolov (via GitHub)" <gi...@apache.org>.
msokolov merged PR #16229:
URL: https://github.com/apache/lucene/pull/16229


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org