From 4ab8e9c26291f8ffdc8c649f01ca3b464fc2ca5c Mon Sep 17 00:00:00 2001 From: Mikhail Khludnev Date: Wed, 21 Sep 2016 22:14:34 +0300 Subject: [PATCH] LUCENE-7452: block join queries' exception message to suggest how to find a doc which violate orthogonality restriction. --- lucene/CHANGES.txt | 3 +++ .../search/join/ToChildBlockJoinQuery.java | 5 +++-- .../search/join/ToParentBlockJoinQuery.java | 21 +++++++++++-------- .../search/join/TestBlockJoinValidation.java | 4 ++-- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index c7d71a268a8..366ad213df0 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -55,6 +55,9 @@ Optimizations Other +* LUCENE-7452: Block join query exception suggests how to find a doc, which + violates orthogonality requirement. (Mikhail Khludnev) + Build * LUCENE-7292: Fix build to use "--release 8" instead of "-release 8" on diff --git a/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java index 53f13b65e49..0b5c19bc84a 100644 --- a/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java +++ b/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java @@ -43,9 +43,10 @@ import org.apache.lucene.util.BitSet; public class ToChildBlockJoinQuery extends Query { /** Message thrown from {@link - * ToChildBlockJoinScorer#validateParentDoc} on mis-use, + * ToChildBlockJoinScorer#validateParentDoc} on misuse, * when the parent query incorrectly returns child docs. */ - static final String INVALID_QUERY_MESSAGE = "Parent query yields document which is not matched by parents filter, docID="; + static final String INVALID_QUERY_MESSAGE = "Parent query must not match any docs besides parent filter. " + + "Combine them as must (+) and must-not (-) clauses to find a problem doc. docID="; static final String ILLEGAL_ADVANCE_ON_PARENT = "Expect to be advanced on child docs only. got docID="; private final BitSetProducer parentsFilter; diff --git a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java index 18a5d20ca29..3abdeeb6933 100644 --- a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java +++ b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java @@ -283,9 +283,7 @@ public class ToParentBlockJoinQuery extends Query { // Parent & child docs are supposed to be // orthogonal: - if (nextChildDoc == parentDoc) { - throw new IllegalStateException("child query must only match non-parent docs, but parent docID=" + nextChildDoc + " matched childScorer=" + childScorer.getClass()); - } + checkOrthogonal(nextChildDoc, parentDoc); //System.out.println(" parentDoc=" + parentDoc); assert parentDoc != DocIdSetIterator.NO_MORE_DOCS; @@ -326,9 +324,7 @@ public class ToParentBlockJoinQuery extends Query { // Parent & child docs are supposed to be // orthogonal: - if (nextChildDoc == parentDoc) { - throw new IllegalStateException("child query must only match non-parent docs, but parent docID=" + nextChildDoc + " matched childScorer=" + childScorer.getClass()); - } + checkOrthogonal(nextChildDoc, parentDoc); switch(scoreMode) { case Avg: @@ -381,9 +377,7 @@ public class ToParentBlockJoinQuery extends Query { } // Parent & child docs are supposed to be orthogonal: - if (nextChildDoc == prevParentDoc) { - throw new IllegalStateException("child query must only match non-parent docs, but parent docID=" + nextChildDoc + " matched childScorer=" + childScorer.getClass()); - } + checkOrthogonal(nextChildDoc, prevParentDoc); final int nd = nextDoc(); //System.out.println(" return nextParentDoc=" + nd); @@ -402,6 +396,15 @@ public class ToParentBlockJoinQuery extends Query { }; } + private void checkOrthogonal(int childDoc, int parentDoc) { + if (childDoc==parentDoc) { + throw new IllegalStateException("Child query must not match same docs with parent filter. " + + "Combine them as must clauses (+) to find a problem doc. " + + "docId=" + nextChildDoc + ", " + childScorer.getClass()); + + } + } + @Override public int docID() { return parentDoc; diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinValidation.java b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinValidation.java index 565578ce295..aa68d09184b 100644 --- a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinValidation.java +++ b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinValidation.java @@ -84,7 +84,7 @@ public class TestBlockJoinValidation extends LuceneTestCase { IllegalStateException expected = expectThrows(IllegalStateException.class, () -> { indexSearcher.search(blockJoinQuery, 1); }); - assertTrue(expected.getMessage() != null && expected.getMessage().contains("child query must only match non-parent docs")); + assertTrue(expected.getMessage() != null && expected.getMessage().contains("Child query must not match same docs with parent filter")); } public void testAdvanceValidationForToParentBjq() throws Exception { @@ -103,7 +103,7 @@ public class TestBlockJoinValidation extends LuceneTestCase { IllegalStateException expected = expectThrows(IllegalStateException.class, () -> { indexSearcher.search(conjunctionQuery.build(), 1); }); - assertTrue(expected.getMessage() != null && expected.getMessage().contains("child query must only match non-parent docs")); + assertTrue(expected.getMessage() != null && expected.getMessage().contains("Child query must not match same docs with parent filter")); } public void testNextDocValidationForToChildBjq() throws Exception {