LUCENE-7452: block join queries' exception message to suggest how to

find a doc which violate orthogonality restriction.
This commit is contained in:
Mikhail Khludnev 2016-09-21 22:14:34 +03:00
parent 4733488ed5
commit 4ab8e9c262
4 changed files with 20 additions and 13 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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 {