{
IndexReader reader = searcher.getIndexReader();
BooleanQuery bquery;
SectionSearchQuery squery;
Scorer scorer;
int count;
// 1. (+f1:aa +f2:aaa)
bquery = new BooleanQuery();
bquery.add(new TermQuery(new Term("f1","aa")), BooleanClause.Occur.MUST);
bquery.add(new TermQuery(new Term("f2","aaa")), BooleanClause.Occur.MUST);
scorer = bquery.weight(searcher).scorer(reader, true, true);
count = 0;
while(scorer.nextDoc() != Scorer.NO_MORE_DOCS) count++;
assertEquals("non-section count mismatch", 4, count);
squery = new SectionSearchQuery(bquery);
scorer = squery.weight(searcher).scorer(reader, true, true);
count = 0;
while(scorer.nextDoc() != Scorer.NO_MORE_DOCS) count++;
assertEquals("seciton count mismatch", 2, count);
// 2. (+f1:bb + f2:aaa)
bquery = new BooleanQuery();
bquery.add(new TermQuery(new Term("f1","bb")), BooleanClause.Occur.MUST);
bquery.add(new TermQuery(new Term("f2","aaa")), BooleanClause.Occur.MUST);
scorer = bquery.weight(searcher).scorer(reader, true, true);
count = 0;
while(scorer.nextDoc() != Scorer.NO_MORE_DOCS) count++;
assertEquals("non-section count mismatch", 4, count);
squery = new SectionSearchQuery(bquery);
scorer = squery.weight(searcher).scorer(reader, true, true);
count = 0;
while(scorer.nextDoc() != Scorer.NO_MORE_DOCS) count++;
assertEquals("seciton count mismatch", 3, count);
// 3. (+f1:aa +f2:bbb)
bquery = new BooleanQuery();
bquery.add(new TermQuery(new Term("f1","aa")), BooleanClause.Occur.MUST);
bquery.add(new TermQuery(new Term("f2","bbb")), BooleanClause.Occur.MUST);
scorer = bquery.weight(searcher).scorer(reader, true, true);
count = 0;
while(scorer.nextDoc() != Scorer.NO_MORE_DOCS) count++;
assertEquals("non-section count mismatch", 3, count);
squery = new SectionSearchQuery(bquery);
scorer = squery.weight(searcher).scorer(reader, true, true);
count = 0;
while(scorer.nextDoc() != Scorer.NO_MORE_DOCS) count++;
assertEquals("seciton count mismatch", 2, count);
// 4. (+f1:aa +(f2:bbb f2:ccc))
BooleanQuery bquery2 = new BooleanQuery();
bquery2.add(new TermQuery(new Term("f2","bbb")), BooleanClause.Occur.SHOULD);
bquery2.add(new TermQuery(new Term("f2","ccc")), BooleanClause.Occur.SHOULD);
bquery = new BooleanQuery();
bquery.add(new TermQuery(new Term("f1","aa")), BooleanClause.Occur.MUST);
bquery.add(bquery2, BooleanClause.Occur.MUST);
scorer = bquery.weight(searcher).scorer(reader, true, true);
count = 0;
while(scorer.nextDoc() != Scorer.NO_MORE_DOCS) count++;
assertEquals("non-section count mismatch", 4, count);
squery = new SectionSearchQuery(bquery);
scorer = squery.weight(searcher).scorer(reader, true, true);
count = 0;
while(scorer.nextDoc() != Scorer.NO_MORE_DOCS) count++;
assertEquals("section count mismatch", 3, count);
}