mirror of https://github.com/apache/lucene.git
LUCENE-5873: BJQ: Throw an error if the top-level filter is not in the child space instead of just asserting.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1649071 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
362ddae754
commit
64d933d34d
|
@ -50,6 +50,7 @@ public class ToChildBlockJoinQuery extends Query {
|
|||
* ToChildBlockJoinScorer#validateParentDoc} on mis-use,
|
||||
* 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 ILLEGAL_ADVANCE_ON_PARENT = "Expect to be advanced on child docs only. got docID=";
|
||||
|
||||
private final BitDocIdSetFilter parentsFilter;
|
||||
private final Query parentQuery;
|
||||
|
@ -279,7 +280,6 @@ public class ToChildBlockJoinQuery extends Query {
|
|||
|
||||
@Override
|
||||
public int advance(int childTarget) throws IOException {
|
||||
assert childTarget >= parentBits.length() || !parentBits.get(childTarget);
|
||||
|
||||
//System.out.println("Q.advance childTarget=" + childTarget);
|
||||
if (childTarget == NO_MORE_DOCS) {
|
||||
|
@ -287,6 +287,10 @@ public class ToChildBlockJoinQuery extends Query {
|
|||
return childDoc = parentDoc = NO_MORE_DOCS;
|
||||
}
|
||||
|
||||
if (parentBits.get(childTarget)) {
|
||||
throw new IllegalStateException(ILLEGAL_ADVANCE_ON_PARENT + childTarget);
|
||||
}
|
||||
|
||||
assert childDoc == -1 || childTarget != parentDoc: "childTarget=" + childTarget;
|
||||
if (childDoc == -1 || childTarget > parentDoc) {
|
||||
// Advance to new parent:
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.apache.lucene.index.IndexWriterConfig;
|
|||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.BooleanClause;
|
||||
import org.apache.lucene.search.BooleanQuery;
|
||||
import org.apache.lucene.search.Filter;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.QueryWrapperFilter;
|
||||
|
@ -112,6 +113,17 @@ public class TestBlockJoinValidation extends LuceneTestCase {
|
|||
indexSearcher.search(blockJoinQuery, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidationForToChildBjqWithChildFilterQuery() throws Exception {
|
||||
Query parentQueryWithRandomChild = createParentQuery();
|
||||
|
||||
ToChildBlockJoinQuery blockJoinQuery = new ToChildBlockJoinQuery(parentQueryWithRandomChild, parentsFilter, false);
|
||||
Filter childFilter = new QueryWrapperFilter(new TermQuery(new Term("common_field", "1")));
|
||||
thrown.expect(IllegalStateException.class);
|
||||
thrown.expectMessage(ToChildBlockJoinQuery.ILLEGAL_ADVANCE_ON_PARENT);
|
||||
indexSearcher.search(blockJoinQuery, childFilter, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdvanceValidationForToChildBjq() throws Exception {
|
||||
int randomChildNumber = getRandomChildNumber(0);
|
||||
|
@ -163,6 +175,7 @@ public class TestBlockJoinValidation extends LuceneTestCase {
|
|||
Document result = new Document();
|
||||
result.add(newStringField("id", createFieldValue(segmentNumber * AMOUNT_OF_PARENT_DOCS + parentNumber), Field.Store.YES));
|
||||
result.add(newStringField("parent", createFieldValue(parentNumber), Field.Store.NO));
|
||||
result.add(newStringField("common_field", "1", Field.Store.NO));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -170,6 +183,7 @@ public class TestBlockJoinValidation extends LuceneTestCase {
|
|||
Document result = new Document();
|
||||
result.add(newStringField("id", createFieldValue(segmentNumber * AMOUNT_OF_PARENT_DOCS + parentNumber, childNumber), Field.Store.YES));
|
||||
result.add(newStringField("child", createFieldValue(childNumber), Field.Store.NO));
|
||||
result.add(newStringField("common_field", "1", Field.Store.NO));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -201,6 +215,10 @@ public class TestBlockJoinValidation extends LuceneTestCase {
|
|||
return childQueryWithRandomParent;
|
||||
}
|
||||
|
||||
private static Query createParentQuery() {
|
||||
return new TermQuery(new Term("id", createFieldValue(getRandomParentId())));
|
||||
}
|
||||
|
||||
private static int getRandomParentId() {
|
||||
return random().nextInt(AMOUNT_OF_PARENT_DOCS * AMOUNT_OF_SEGMENTS);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue