mirror of https://github.com/apache/lucene.git
Fix TestBlockJoinValidation expectations.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1686813 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fdeffbb536
commit
c0fd50b2ed
|
@ -27,16 +27,22 @@ import org.apache.lucene.index.DirectoryReader;
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
import org.apache.lucene.index.IndexWriter;
|
import org.apache.lucene.index.IndexWriter;
|
||||||
import org.apache.lucene.index.IndexWriterConfig;
|
import org.apache.lucene.index.IndexWriterConfig;
|
||||||
|
import org.apache.lucene.index.LeafReaderContext;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
import org.apache.lucene.search.BooleanClause;
|
import org.apache.lucene.search.BooleanClause;
|
||||||
import org.apache.lucene.search.BooleanQuery;
|
import org.apache.lucene.search.BooleanQuery;
|
||||||
import org.apache.lucene.search.IndexSearcher;
|
import org.apache.lucene.search.IndexSearcher;
|
||||||
|
import org.apache.lucene.search.MatchAllDocsQuery;
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
import org.apache.lucene.search.QueryWrapperFilter;
|
import org.apache.lucene.search.QueryWrapperFilter;
|
||||||
|
import org.apache.lucene.search.Scorer;
|
||||||
import org.apache.lucene.search.TermQuery;
|
import org.apache.lucene.search.TermQuery;
|
||||||
|
import org.apache.lucene.search.Weight;
|
||||||
import org.apache.lucene.search.WildcardQuery;
|
import org.apache.lucene.search.WildcardQuery;
|
||||||
import org.apache.lucene.store.Directory;
|
import org.apache.lucene.store.Directory;
|
||||||
|
import org.apache.lucene.util.Bits;
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
import org.apache.lucene.util.LuceneTestCase;
|
||||||
|
import org.apache.lucene.util.TestUtil;
|
||||||
|
|
||||||
public class TestBlockJoinValidation extends LuceneTestCase {
|
public class TestBlockJoinValidation extends LuceneTestCase {
|
||||||
|
|
||||||
|
@ -120,21 +126,23 @@ public class TestBlockJoinValidation extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAdvanceValidationForToChildBjq() throws Exception {
|
public void testAdvanceValidationForToChildBjq() throws Exception {
|
||||||
int randomChildNumber = getRandomChildNumber(0);
|
Query parentQuery = new MatchAllDocsQuery();
|
||||||
// we need to make advance method meet wrong document, so random child number
|
ToChildBlockJoinQuery blockJoinQuery = new ToChildBlockJoinQuery(parentQuery, parentsFilter);
|
||||||
// in BJQ must be greater than child number in Boolean clause
|
|
||||||
int nextRandomChildNumber = getRandomChildNumber(randomChildNumber);
|
final LeafReaderContext context = indexSearcher.getIndexReader().leaves().get(0);
|
||||||
Query parentQueryWithRandomChild = createParentsQueryWithOneChild(nextRandomChildNumber);
|
Weight weight = indexSearcher.createNormalizedWeight(blockJoinQuery, true);
|
||||||
ToChildBlockJoinQuery blockJoinQuery = new ToChildBlockJoinQuery(parentQueryWithRandomChild, parentsFilter);
|
Scorer scorer = weight.scorer(context, context.reader().getLiveDocs());
|
||||||
// advance() method is used by ConjunctionScorer, so we need to create Boolean conjunction query
|
final Bits parentDocs = parentsFilter.getDocIdSet(context).bits();
|
||||||
BooleanQuery.Builder conjunctionQuery = new BooleanQuery.Builder();
|
|
||||||
WildcardQuery childQuery = new WildcardQuery(new Term("child", createFieldValue(randomChildNumber)));
|
int target;
|
||||||
conjunctionQuery.add(childQuery, BooleanClause.Occur.MUST);
|
do {
|
||||||
conjunctionQuery.add(blockJoinQuery, BooleanClause.Occur.MUST);
|
// make the parent scorer advance to a doc ID which is not a parent
|
||||||
|
target = TestUtil.nextInt(random(), 0, context.reader().maxDoc() - 2);
|
||||||
|
} while (parentDocs.get(target + 1));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
indexSearcher.search(conjunctionQuery.build(), 1);
|
scorer.advance(target);
|
||||||
fail("didn't get expected exception");
|
fail();
|
||||||
} catch (IllegalStateException expected) {
|
} catch (IllegalStateException expected) {
|
||||||
assertTrue(expected.getMessage() != null && expected.getMessage().contains(ToChildBlockJoinQuery.INVALID_QUERY_MESSAGE));
|
assertTrue(expected.getMessage() != null && expected.getMessage().contains(ToChildBlockJoinQuery.INVALID_QUERY_MESSAGE));
|
||||||
}
|
}
|
||||||
|
@ -205,10 +213,6 @@ public class TestBlockJoinValidation extends LuceneTestCase {
|
||||||
return childQueryWithRandomParent.build();
|
return childQueryWithRandomParent.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Query createParentQuery() {
|
|
||||||
return new TermQuery(new Term("id", createFieldValue(getRandomParentId())));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int getRandomParentId() {
|
private static int getRandomParentId() {
|
||||||
return random().nextInt(AMOUNT_OF_PARENT_DOCS * AMOUNT_OF_SEGMENTS);
|
return random().nextInt(AMOUNT_OF_PARENT_DOCS * AMOUNT_OF_SEGMENTS);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue