You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2015/07/29 09:09:41 UTC

svn commit: r1693190 [6/8] - in /lucene/dev/branches/branch_5x: ./ lucene/ lucene/analysis/common/src/test/org/apache/lucene/analysis/shingle/ lucene/benchmark/ lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/ lucene/benchmark/src/ja...

Modified: lucene/dev/branches/branch_5x/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java (original)
+++ lucene/dev/branches/branch_5x/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java Wed Jul 29 07:09:39 2015
@@ -135,17 +135,17 @@ public class TestBlockJoin extends Lucen
     BitSetProducer parentsFilter = new QueryBitSetProducer(new TermQuery(new Term("docType", "resume")));
     CheckJoinIndex.check(r, parentsFilter);
 
-    BooleanQuery childQuery = new BooleanQuery();
+    BooleanQuery.Builder childQuery = new BooleanQuery.Builder();
     childQuery.add(new BooleanClause(new TermQuery(new Term("skill", "java")), Occur.MUST));
     childQuery.add(new BooleanClause(NumericRangeQuery.newIntRange("year", 2006, 2011, true, true), Occur.MUST));
 
-    ToParentBlockJoinQuery childJoinQuery = new ToParentBlockJoinQuery(childQuery, parentsFilter, ScoreMode.Avg);
+    ToParentBlockJoinQuery childJoinQuery = new ToParentBlockJoinQuery(childQuery.build(), parentsFilter, ScoreMode.Avg);
 
-    BooleanQuery fullQuery = new BooleanQuery();
+    BooleanQuery.Builder fullQuery = new BooleanQuery.Builder();
     fullQuery.add(new BooleanClause(childJoinQuery, Occur.MUST));
     fullQuery.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST));
     ToParentBlockJoinCollector c = new ToParentBlockJoinCollector(Sort.RELEVANCE, 1, true, true);
-    s.search(fullQuery, c);
+    s.search(fullQuery.build(), c);
     TopGroups<Integer> results = c.getTopGroups(childJoinQuery, null, 0, 10, 0, true);
     assertFalse(Float.isNaN(results.maxScore));
     assertEquals(1, results.totalGroupedHitCount);
@@ -189,7 +189,7 @@ public class TestBlockJoin extends Lucen
     CheckJoinIndex.check(r, parentsFilter);
 
     // Define child document criteria (finds an example of relevant work experience)
-    BooleanQuery childQuery = new BooleanQuery();
+    BooleanQuery.Builder childQuery = new BooleanQuery.Builder();
     childQuery.add(new BooleanClause(new TermQuery(new Term("skill", "java")), Occur.MUST));
     childQuery.add(new BooleanClause(NumericRangeQuery.newIntRange("year", 2006, 2011, true, true), Occur.MUST));
 
@@ -198,16 +198,16 @@ public class TestBlockJoin extends Lucen
 
     // Wrap the child document query to 'join' any matches
     // up to corresponding parent:
-    ToParentBlockJoinQuery childJoinQuery = new ToParentBlockJoinQuery(childQuery, parentsFilter, ScoreMode.Avg);
+    ToParentBlockJoinQuery childJoinQuery = new ToParentBlockJoinQuery(childQuery.build(), parentsFilter, ScoreMode.Avg);
 
     // Combine the parent and nested child queries into a single query for a candidate
-    BooleanQuery fullQuery = new BooleanQuery();
+    BooleanQuery.Builder fullQuery = new BooleanQuery.Builder();
     fullQuery.add(new BooleanClause(parentQuery, Occur.MUST));
     fullQuery.add(new BooleanClause(childJoinQuery, Occur.MUST));
 
     ToParentBlockJoinCollector c = new ToParentBlockJoinCollector(Sort.RELEVANCE, 1, true, true);
 
-    s.search(fullQuery, c);
+    s.search(fullQuery.build(), c);
     
     TopGroups<Integer> results = c.getTopGroups(childJoinQuery, null, 0, 10, 0, true);
     assertFalse(Float.isNaN(results.maxScore));
@@ -232,12 +232,12 @@ public class TestBlockJoin extends Lucen
 
     // Now join "up" (map parent hits to child docs) instead...:
     ToChildBlockJoinQuery parentJoinQuery = new ToChildBlockJoinQuery(parentQuery, parentsFilter);
-    BooleanQuery fullChildQuery = new BooleanQuery();
+    BooleanQuery.Builder fullChildQuery = new BooleanQuery.Builder();
     fullChildQuery.add(new BooleanClause(parentJoinQuery, Occur.MUST));
-    fullChildQuery.add(new BooleanClause(childQuery, Occur.MUST));
+    fullChildQuery.add(new BooleanClause(childQuery.build(), Occur.MUST));
     
     //System.out.println("FULL: " + fullChildQuery);
-    TopDocs hits = s.search(fullChildQuery, 10);
+    TopDocs hits = s.search(fullChildQuery.build(), 10);
     assertEquals(1, hits.totalHits);
     childDoc = s.doc(hits.scoreDocs[0].doc);
     //System.out.println("CHILD = " + childDoc + " docID=" + hits.scoreDocs[0].doc);
@@ -246,7 +246,7 @@ public class TestBlockJoin extends Lucen
     assertEquals("Lisa", getParentDoc(r, parentsFilter, hits.scoreDocs[0].doc).get("name"));
 
     // Test with filter on child docs:
-    assertEquals(0, s.search(new FilteredQuery(fullChildQuery,
+    assertEquals(0, s.search(new FilteredQuery(fullChildQuery.build(),
                              new QueryWrapperFilter(new TermQuery(new Term("skill", "foosball")))),
                              1).totalHits);
     
@@ -343,7 +343,7 @@ public class TestBlockJoin extends Lucen
     CheckJoinIndex.check(r, parentsFilter);
 
     // Define child document criteria (finds an example of relevant work experience)
-    BooleanQuery childQuery = new BooleanQuery();
+    BooleanQuery.Builder childQuery = new BooleanQuery.Builder();
     childQuery.add(new BooleanClause(new TermQuery(new Term("skill", "java")), Occur.MUST));
     childQuery.add(new BooleanClause(NumericRangeQuery.newIntRange("year", 2006, 2011, true, true), Occur.MUST));
 
@@ -352,14 +352,14 @@ public class TestBlockJoin extends Lucen
       
     // Wrap the child document query to 'join' any matches
     // up to corresponding parent:
-    ToParentBlockJoinQuery childJoinQuery = new ToParentBlockJoinQuery(childQuery, parentsFilter, ScoreMode.Avg);
+    ToParentBlockJoinQuery childJoinQuery = new ToParentBlockJoinQuery(childQuery.build(), parentsFilter, ScoreMode.Avg);
       
     assertEquals("no filter - both passed", 2, s.search(childJoinQuery, 10).totalHits);
 
-    BooleanQuery query = new BooleanQuery();
+    BooleanQuery.Builder query = new BooleanQuery.Builder();
     query.add(childJoinQuery, Occur.MUST);
     query.add(new TermQuery(new Term("docType", "resume")), Occur.FILTER);
-    assertEquals("dummy filter passes everyone ", 2, s.search(query, 10).totalHits);
+    assertEquals("dummy filter passes everyone ", 2, s.search(query.build(), 10).totalHits);
       
     // not found test
     assertEquals("noone live there", 0, s.search(new FilteredQuery(childJoinQuery, new BitDocIdSetCachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("country", "Oz"))))), 1).totalHits);
@@ -383,11 +383,11 @@ public class TestBlockJoin extends Lucen
     assertEquals("java skills in US", 1, s.search(new FilteredQuery(new ToChildBlockJoinQuery(us, parentsFilter),
         skill("java")), 10).totalHits );
 
-    BooleanQuery rubyPython = new BooleanQuery();
+    BooleanQuery.Builder rubyPython = new BooleanQuery.Builder();
     rubyPython.add(new TermQuery(new Term("skill", "ruby")), Occur.SHOULD);
     rubyPython.add(new TermQuery(new Term("skill", "python")), Occur.SHOULD);
     assertEquals("ruby skills in US", 1, s.search(new FilteredQuery(new ToChildBlockJoinQuery(us, parentsFilter),
-                                          new QueryWrapperFilter(rubyPython)), 10).totalHits );
+                                          new QueryWrapperFilter(rubyPython.build())), 10).totalHits );
 
     r.close();
     dir.close();
@@ -417,9 +417,10 @@ public class TestBlockJoin extends Lucen
     ToParentBlockJoinQuery q = new ToParentBlockJoinQuery(new MatchNoDocsQuery(), new QueryBitSetProducer(new MatchAllDocsQuery()), ScoreMode.Avg);
     QueryUtils.check(random(), q, s);
     s.search(q, 10);
-    BooleanQuery bq = new BooleanQuery();
-    bq.setBoost(2f); // we boost the BQ
-    bq.add(q, BooleanClause.Occur.MUST);
+    BooleanQuery.Builder bqB = new BooleanQuery.Builder();
+    bqB.add(q, BooleanClause.Occur.MUST);
+    BooleanQuery bq = bqB.build();
+    bq.setBoost(2f);
     s.search(bq, 10);
     r.close();
     dir.close();
@@ -640,8 +641,7 @@ public class TestBlockJoin extends Lucen
         childQuery = new TermQuery(new Term("child" + childFieldID,
                                             childFields[childFieldID][random().nextInt(childFields[childFieldID].length)]));
       } else if (random().nextInt(3) == 2) {
-        BooleanQuery bq = new BooleanQuery();
-        childQuery = bq;
+        BooleanQuery.Builder bq = new BooleanQuery.Builder();
         final int numClauses = TestUtil.nextInt(random(), 2, 4);
         boolean didMust = false;
         for(int clauseIDX=0;clauseIDX<numClauses;clauseIDX++) {
@@ -659,15 +659,16 @@ public class TestBlockJoin extends Lucen
           }
           bq.add(clause, occur);
         }
+        childQuery = bq.build();
       } else {
-        BooleanQuery bq = new BooleanQuery();
-        childQuery = bq;
+        BooleanQuery.Builder bq = new BooleanQuery.Builder();
         
         bq.add(new TermQuery(randomChildTerm(childFields[0])),
                BooleanClause.Occur.MUST);
         final int childFieldID = TestUtil.nextInt(random(), 1, childFields.length - 1);
         bq.add(new TermQuery(new Term("child" + childFieldID, childFields[childFieldID][random().nextInt(childFields[childFieldID].length)])),
                random().nextBoolean() ? BooleanClause.Occur.MUST : BooleanClause.Occur.MUST_NOT);
+        childQuery = bq.build();
       }
 
 
@@ -687,8 +688,7 @@ public class TestBlockJoin extends Lucen
         parentJoinQuery = childJoinQuery;
       } else {
         // AND parent field w/ child field
-        final BooleanQuery bq = new BooleanQuery();
-        parentJoinQuery = bq;
+        final BooleanQuery.Builder bq = new BooleanQuery.Builder();
         final Term parentTerm = randomParentTerm(parentFields[0]);
         if (random().nextBoolean()) {
           bq.add(childJoinQuery, BooleanClause.Occur.MUST);
@@ -700,8 +700,7 @@ public class TestBlockJoin extends Lucen
           bq.add(childJoinQuery, BooleanClause.Occur.MUST);
         }
 
-        final BooleanQuery bq2 = new BooleanQuery();
-        parentQuery = bq2;
+        final BooleanQuery.Builder bq2 = new BooleanQuery.Builder();
         if (random().nextBoolean()) {
           bq2.add(childQuery, BooleanClause.Occur.MUST);
           bq2.add(new TermQuery(parentTerm),
@@ -711,6 +710,8 @@ public class TestBlockJoin extends Lucen
                   BooleanClause.Occur.MUST);
           bq2.add(childQuery, BooleanClause.Occur.MUST);
         }
+        parentJoinQuery = bq.build();
+        parentQuery = bq2.build();
       }
 
       final Sort parentSort = getRandomSort("parent", parentFields.length);
@@ -823,8 +824,7 @@ public class TestBlockJoin extends Lucen
         parentQuery2 = new TermQuery(new Term("parent" + fieldID,
                                               parentFields[fieldID][random().nextInt(parentFields[fieldID].length)]));
       } else if (random().nextInt(3) == 2) {
-        BooleanQuery bq = new BooleanQuery();
-        parentQuery2 = bq;
+        BooleanQuery.Builder bq = new BooleanQuery.Builder();
         final int numClauses = TestUtil.nextInt(random(), 2, 4);
         boolean didMust = false;
         for(int clauseIDX=0;clauseIDX<numClauses;clauseIDX++) {
@@ -842,15 +842,16 @@ public class TestBlockJoin extends Lucen
           }
           bq.add(clause, occur);
         }
+        parentQuery2 = bq.build();
       } else {
-        BooleanQuery bq = new BooleanQuery();
-        parentQuery2 = bq;
+        BooleanQuery.Builder bq = new BooleanQuery.Builder();
         
         bq.add(new TermQuery(randomParentTerm(parentFields[0])),
                BooleanClause.Occur.MUST);
         final int fieldID = TestUtil.nextInt(random(), 1, parentFields.length - 1);
         bq.add(new TermQuery(new Term("parent" + fieldID, parentFields[fieldID][random().nextInt(parentFields[fieldID].length)])),
                random().nextBoolean() ? BooleanClause.Occur.MUST : BooleanClause.Occur.MUST_NOT);
+        parentQuery2 = bq.build();
       }
 
       if (VERBOSE) {
@@ -880,8 +881,7 @@ public class TestBlockJoin extends Lucen
                   ? new BitDocIdSetCachingWrapperFilter(f): f);
         } else {
           // AND child field w/ parent query:
-          final BooleanQuery bq = new BooleanQuery();
-          childJoinQuery2 = bq;
+          final BooleanQuery.Builder bq = new BooleanQuery.Builder();
           if (random().nextBoolean()) {
             bq.add(parentJoinQuery2, BooleanClause.Occur.MUST);
             bq.add(new TermQuery(childTerm),
@@ -891,6 +891,7 @@ public class TestBlockJoin extends Lucen
                    BooleanClause.Occur.MUST);
             bq.add(parentJoinQuery2, BooleanClause.Occur.MUST);
           }
+          childJoinQuery2 = bq.build();
         }
         
         if (random().nextBoolean()) { // filtered case
@@ -898,8 +899,7 @@ public class TestBlockJoin extends Lucen
           childQuery2 = new FilteredQuery(childQuery2, random().nextBoolean()
                   ? new BitDocIdSetCachingWrapperFilter(f): f);
         } else {
-          final BooleanQuery bq2 = new BooleanQuery();
-          childQuery2 = bq2;
+          final BooleanQuery.Builder bq2 = new BooleanQuery.Builder();
           if (random().nextBoolean()) {
             bq2.add(parentQuery2, BooleanClause.Occur.MUST);
             bq2.add(new TermQuery(childTerm),
@@ -909,6 +909,7 @@ public class TestBlockJoin extends Lucen
                     BooleanClause.Occur.MUST);
             bq2.add(parentQuery2, BooleanClause.Occur.MUST);
           }
+          childQuery2 = bq2.build();
         }
       }
 
@@ -1035,11 +1036,11 @@ public class TestBlockJoin extends Lucen
     CheckJoinIndex.check(s.getIndexReader(), parentsFilter);
 
     // Define child document criteria (finds an example of relevant work experience)
-    BooleanQuery childJobQuery = new BooleanQuery();
+    BooleanQuery.Builder childJobQuery = new BooleanQuery.Builder();
     childJobQuery.add(new BooleanClause(new TermQuery(new Term("skill", "java")), Occur.MUST));
     childJobQuery.add(new BooleanClause(NumericRangeQuery.newIntRange("year", 2006, 2011, true, true), Occur.MUST));
 
-    BooleanQuery childQualificationQuery = new BooleanQuery();
+    BooleanQuery.Builder childQualificationQuery = new BooleanQuery.Builder();
     childQualificationQuery.add(new BooleanClause(new TermQuery(new Term("qualification", "maths")), Occur.MUST));
     childQualificationQuery.add(new BooleanClause(NumericRangeQuery.newIntRange("year", 1980, 2000, true, true), Occur.MUST));
 
@@ -1049,11 +1050,11 @@ public class TestBlockJoin extends Lucen
 
     // Wrap the child document query to 'join' any matches
     // up to corresponding parent:
-    ToParentBlockJoinQuery childJobJoinQuery = new ToParentBlockJoinQuery(childJobQuery, parentsFilter, ScoreMode.Avg);
-    ToParentBlockJoinQuery childQualificationJoinQuery = new ToParentBlockJoinQuery(childQualificationQuery, parentsFilter, ScoreMode.Avg);
+    ToParentBlockJoinQuery childJobJoinQuery = new ToParentBlockJoinQuery(childJobQuery.build(), parentsFilter, ScoreMode.Avg);
+    ToParentBlockJoinQuery childQualificationJoinQuery = new ToParentBlockJoinQuery(childQualificationQuery.build(), parentsFilter, ScoreMode.Avg);
 
     // Combine the parent and nested child queries into a single query for a candidate
-    BooleanQuery fullQuery = new BooleanQuery();
+    BooleanQuery.Builder fullQuery = new BooleanQuery.Builder();
     fullQuery.add(new BooleanClause(parentQuery, Occur.MUST));
     fullQuery.add(new BooleanClause(childJobJoinQuery, Occur.MUST));
     fullQuery.add(new BooleanClause(childQualificationJoinQuery, Occur.MUST));
@@ -1062,7 +1063,7 @@ public class TestBlockJoin extends Lucen
     // each resume hit in the top N (sorted by score):
     ToParentBlockJoinCollector c = new ToParentBlockJoinCollector(Sort.RELEVANCE, 10, true, false);
 
-    s.search(fullQuery, c);
+    s.search(fullQuery.build(), c);
 
     // Examine "Job" children
     TopGroups<Integer> jobResults = c.getTopGroups(childJobJoinQuery, null, 0, 10, 0, true);
@@ -1184,13 +1185,13 @@ public class TestBlockJoin extends Lucen
     CheckJoinIndex.check(s.getIndexReader(), parentsFilter);
 
     // Define child document criteria (finds an example of relevant work experience)
-    BooleanQuery childQuery = new BooleanQuery();
+    BooleanQuery.Builder childQuery = new BooleanQuery.Builder();
     childQuery.add(new BooleanClause(new TermQuery(new Term("skill", "java")), Occur.MUST));
     childQuery.add(new BooleanClause(NumericRangeQuery.newIntRange("year", 2006, 2011, true, true), Occur.MUST));
 
     // Wrap the child document query to 'join' any matches
     // up to corresponding parent:
-    ToParentBlockJoinQuery childJoinQuery = new ToParentBlockJoinQuery(childQuery, parentsFilter, ScoreMode.Avg);
+    ToParentBlockJoinQuery childJoinQuery = new ToParentBlockJoinQuery(childQuery.build(), parentsFilter, ScoreMode.Avg);
 
     ToParentBlockJoinCollector c = new ToParentBlockJoinCollector(Sort.RELEVANCE, 2, true, true);
     s.search(childJoinQuery, c);
@@ -1290,13 +1291,13 @@ public class TestBlockJoin extends Lucen
     BitSetProducer parentsFilter = new QueryBitSetProducer(new TermQuery(new Term("isParent", "yes")));
     CheckJoinIndex.check(r, parentsFilter);
     ToParentBlockJoinQuery childJoinQuery = new ToParentBlockJoinQuery(childQuery, parentsFilter, ScoreMode.Avg);
-    BooleanQuery parentQuery = new BooleanQuery();
+    BooleanQuery.Builder parentQuery = new BooleanQuery.Builder();
     parentQuery.add(childJoinQuery, Occur.SHOULD);
     parentQuery.add(new TermQuery(new Term("parentText", "text")), Occur.SHOULD);
 
     ToParentBlockJoinCollector c = new ToParentBlockJoinCollector(new Sort(new SortField("parentID", SortField.Type.STRING)),
                                                                   10, true, true);
-    searcher.search(parentQuery, c);
+    searcher.search(parentQuery.build(), c);
     TopGroups<Integer> groups = c.getTopGroups(childJoinQuery, null, 0, 10, 0, false);
 
     // Two parents:
@@ -1361,13 +1362,13 @@ public class TestBlockJoin extends Lucen
     BitSetProducer parentsFilter = new QueryBitSetProducer(new TermQuery(new Term("isParent", "yes")));
     CheckJoinIndex.check(r, parentsFilter);
     ToParentBlockJoinQuery childJoinQuery = new ToParentBlockJoinQuery(childQuery, parentsFilter, ScoreMode.Avg);
-    BooleanQuery parentQuery = new BooleanQuery();
+    BooleanQuery.Builder parentQuery = new BooleanQuery.Builder();
     parentQuery.add(childJoinQuery, Occur.SHOULD);
     parentQuery.add(new TermQuery(new Term("parentText", "text")), Occur.SHOULD);
 
     ToParentBlockJoinCollector c = new ToParentBlockJoinCollector(new Sort(new SortField("parentID", SortField.Type.STRING)),
                                                                   10, true, true);
-    searcher.search(parentQuery, c);
+    searcher.search(parentQuery.build(), c);
     TopGroups<Integer> groups = c.getTopGroups(childJoinQuery, null, 0, 10, 0, false);
 
     // Two parents:
@@ -1427,7 +1428,7 @@ public class TestBlockJoin extends Lucen
     BitSetProducer parentsFilter = new QueryBitSetProducer(new TermQuery(new Term("isParent", "yes")));
     CheckJoinIndex.check(r, parentsFilter);
     ToParentBlockJoinQuery childJoinQuery = new ToParentBlockJoinQuery(childQuery, parentsFilter, ScoreMode.Avg);
-    BooleanQuery parentQuery = new BooleanQuery();
+    BooleanQuery.Builder parentQuery = new BooleanQuery.Builder();
     parentQuery.add(childJoinQuery, Occur.SHOULD);
     parentQuery.add(new TermQuery(new Term("parentText", "text")), Occur.SHOULD);
 
@@ -1435,7 +1436,7 @@ public class TestBlockJoin extends Lucen
                                                                   10, true, true);
 
     try {
-      newSearcher(r).search(parentQuery, c);
+      newSearcher(r).search(parentQuery.build(), c);
       fail("should have hit exception");
     } catch (IllegalStateException ise) {
       // expected
@@ -1517,14 +1518,14 @@ public class TestBlockJoin extends Lucen
     final Query toChild = new ToChildBlockJoinQuery(new TermQuery(new Term("foo_parent", "bar")), parentsFilter);
     final Query childQuery = new TermQuery(new Term("foo_child", "baz"));
 
-    BooleanQuery bq1 = new BooleanQuery();
+    BooleanQuery.Builder bq1 = new BooleanQuery.Builder();
     bq1.add(toChild, Occur.MUST);
     bq1.add(childQuery, Occur.MUST);
-    BooleanQuery bq2 = new BooleanQuery();
+    BooleanQuery.Builder bq2 = new BooleanQuery.Builder();
     bq2.add(toChild, Occur.MUST);
     bq2.add(new RandomApproximationQuery(childQuery, random()), Occur.MUST);
 
-    assertEquals(searcher.count(bq1), searcher.count(bq2));
+    assertEquals(searcher.count(bq1.build()), searcher.count(bq2.build()));
 
     searcher.getIndexReader().close();
     w.close();

Modified: lucene/dev/branches/branch_5x/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinValidation.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinValidation.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinValidation.java (original)
+++ lucene/dev/branches/branch_5x/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinValidation.java Wed Jul 29 07:09:39 2015
@@ -98,13 +98,13 @@ public class TestBlockJoinValidation ext
     Query parentQueryWithRandomChild = createChildrenQueryWithOneParent(nextRandomChildNumber);
     ToParentBlockJoinQuery blockJoinQuery = new ToParentBlockJoinQuery(parentQueryWithRandomChild, parentsFilter, ScoreMode.None);
     // advance() method is used by ConjunctionScorer, so we need to create Boolean conjunction query
-    BooleanQuery conjunctionQuery = new BooleanQuery();
+    BooleanQuery.Builder conjunctionQuery = new BooleanQuery.Builder();
     WildcardQuery childQuery = new WildcardQuery(new Term("child", createFieldValue(randomChildNumber)));
     conjunctionQuery.add(new BooleanClause(childQuery, BooleanClause.Occur.MUST));
     conjunctionQuery.add(new BooleanClause(blockJoinQuery, BooleanClause.Occur.MUST));
     
     try {
-      indexSearcher.search(conjunctionQuery, 1);
+      indexSearcher.search(conjunctionQuery.build(), 1);
       fail("didn't get expected exception");
     } catch (IllegalStateException expected) {
       assertTrue(expected.getMessage() != null && expected.getMessage().contains("child query must only match non-parent docs"));
@@ -198,18 +198,18 @@ public class TestBlockJoinValidation ext
   private static Query createChildrenQueryWithOneParent(int childNumber) {
     TermQuery childQuery = new TermQuery(new Term("child", createFieldValue(childNumber)));
     Query randomParentQuery = new TermQuery(new Term("id", createFieldValue(getRandomParentId())));
-    BooleanQuery childrenQueryWithRandomParent = new BooleanQuery();
+    BooleanQuery.Builder childrenQueryWithRandomParent = new BooleanQuery.Builder();
     childrenQueryWithRandomParent.add(new BooleanClause(childQuery, BooleanClause.Occur.SHOULD));
     childrenQueryWithRandomParent.add(new BooleanClause(randomParentQuery, BooleanClause.Occur.SHOULD));
-    return childrenQueryWithRandomParent;
+    return childrenQueryWithRandomParent.build();
   }
 
   private static Query createParentsQueryWithOneChild(int randomChildNumber) {
-    BooleanQuery childQueryWithRandomParent = new BooleanQuery();
+    BooleanQuery.Builder childQueryWithRandomParent = new BooleanQuery.Builder();
     Query parentsQuery = new TermQuery(new Term("parent", createFieldValue(getRandomParentNumber())));
     childQueryWithRandomParent.add(new BooleanClause(parentsQuery, BooleanClause.Occur.SHOULD));
     childQueryWithRandomParent.add(new BooleanClause(randomChildQuery(randomChildNumber), BooleanClause.Occur.SHOULD));
-    return childQueryWithRandomParent;
+    return childQueryWithRandomParent.build();
   }
 
   private static int getRandomParentId() {

Modified: lucene/dev/branches/branch_5x/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java (original)
+++ lucene/dev/branches/branch_5x/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java Wed Jul 29 07:09:39 2015
@@ -312,17 +312,17 @@ public class TestJoinUtil extends Lucene
 
       final Query joinQuery;
       if (from) {
-        BooleanQuery fromQuery = new BooleanQuery();
+        BooleanQuery.Builder fromQuery = new BooleanQuery.Builder();
         fromQuery.add(new TermQuery(new Term("type", "from")), BooleanClause.Occur.FILTER);
         fromQuery.add(actualQuery, BooleanClause.Occur.MUST);
         Query toQuery = new TermQuery(new Term("type", "to"));
-        joinQuery = JoinUtil.createJoinQuery("join_field", fromQuery, toQuery, indexSearcher, scoreMode, context.ordinalMap);
+        joinQuery = JoinUtil.createJoinQuery("join_field", fromQuery.build(), toQuery, indexSearcher, scoreMode, context.ordinalMap);
       } else {
-        BooleanQuery fromQuery = new BooleanQuery();
+        BooleanQuery.Builder fromQuery = new BooleanQuery.Builder();
         fromQuery.add(new TermQuery(new Term("type", "to")), BooleanClause.Occur.FILTER);
         fromQuery.add(actualQuery, BooleanClause.Occur.MUST);
         Query toQuery = new TermQuery(new Term("type", "from"));
-        joinQuery = JoinUtil.createJoinQuery("join_field", fromQuery, toQuery, indexSearcher, scoreMode, context.ordinalMap);
+        joinQuery = JoinUtil.createJoinQuery("join_field", fromQuery.build(), toQuery, indexSearcher, scoreMode, context.ordinalMap);
       }
       if (VERBOSE) {
         System.out.println("joinQuery=" + joinQuery);
@@ -438,10 +438,10 @@ public class TestJoinUtil extends Lucene
     MultiDocValues.OrdinalMap ordinalMap = MultiDocValues.OrdinalMap.build(
         searcher.getIndexReader().getCoreCacheKey(), values, PackedInts.DEFAULT
     );
-    BooleanQuery fromQuery = new BooleanQuery();
+    BooleanQuery.Builder fromQuery = new BooleanQuery.Builder();
     fromQuery.add(priceQuery, BooleanClause.Occur.MUST);
     Query toQuery = new TermQuery(new Term("type", "to"));
-    Query joinQuery = JoinUtil.createJoinQuery("join_field", fromQuery, toQuery, searcher, ScoreMode.Min, ordinalMap);
+    Query joinQuery = JoinUtil.createJoinQuery("join_field", fromQuery.build(), toQuery, searcher, ScoreMode.Min, ordinalMap);
     TopDocs topDocs = searcher.search(joinQuery, numParents);
     assertEquals(numParents, topDocs.totalHits);
     for (int i = 0; i < topDocs.scoreDocs.length; i++) {
@@ -450,7 +450,7 @@ public class TestJoinUtil extends Lucene
       assertEquals(lowestScoresPerParent.get(id), scoreDoc.score, 0f);
     }
 
-    joinQuery = JoinUtil.createJoinQuery("join_field", fromQuery, toQuery, searcher, ScoreMode.Max, ordinalMap);
+    joinQuery = JoinUtil.createJoinQuery("join_field", fromQuery.build(), toQuery, searcher, ScoreMode.Max, ordinalMap);
     topDocs = searcher.search(joinQuery, numParents);
     assertEquals(numParents, topDocs.totalHits);
     for (int i = 0; i < topDocs.scoreDocs.length; i++) {
@@ -656,11 +656,11 @@ public class TestJoinUtil extends Lucene
     Query joinQuery =
         JoinUtil.createJoinQuery(idField, false, toField, new TermQuery(new Term("description", "random")), indexSearcher, ScoreMode.Avg);
 
-    BooleanQuery bq = new BooleanQuery();
+    BooleanQuery.Builder bq = new BooleanQuery.Builder();
     bq.add(joinQuery, BooleanClause.Occur.SHOULD);
     bq.add(new TermQuery(new Term("id", "3")), BooleanClause.Occur.SHOULD);
 
-    indexSearcher.search(bq, new SimpleCollector() {
+    indexSearcher.search(bq.build(), new SimpleCollector() {
         boolean sawFive;
         @Override
         public void collect(int docID) {

Modified: lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/search/TestDiversifiedTopDocsCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/search/TestDiversifiedTopDocsCollector.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/search/TestDiversifiedTopDocsCollector.java (original)
+++ lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/search/TestDiversifiedTopDocsCollector.java Wed Jul 29 07:09:39 2015
@@ -307,7 +307,7 @@ public class TestDiversifiedTopDocsColle
   }
 
   private Query getTestQuery() {
-    BooleanQuery testQuery = new BooleanQuery();
+    BooleanQuery.Builder testQuery = new BooleanQuery.Builder();
     testQuery.add(new BooleanClause(new TermQuery(new Term("year", "1966")),
         Occur.SHOULD));
     testQuery.add(new BooleanClause(new TermQuery(new Term("year", "1967")),
@@ -316,7 +316,7 @@ public class TestDiversifiedTopDocsColle
         Occur.SHOULD));
     testQuery.add(new BooleanClause(new TermQuery(new Term("year", "1969")),
         Occur.SHOULD));
-    return testQuery;
+    return testQuery.build();
   }
 
   @Override

Modified: lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCacheSort.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCacheSort.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCacheSort.java (original)
+++ lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCacheSort.java Wed Jul 29 07:09:39 2015
@@ -1204,10 +1204,10 @@ public class TestFieldCacheSort extends
     IndexSearcher searcher = newSearcher(ir);
     Sort sort = new Sort(SortField.FIELD_SCORE);
 
-    final BooleanQuery bq = new BooleanQuery();
+    final BooleanQuery.Builder bq = new BooleanQuery.Builder();
     bq.add(new TermQuery(new Term("value", "foo")), Occur.SHOULD);
     bq.add(new MatchAllDocsQuery(), Occur.SHOULD);
-    TopDocs td = searcher.search(bq, 10, sort);
+    TopDocs td = searcher.search(bq.build(), 10, sort);
     assertEquals(2, td.totalHits);
     assertEquals(1, td.scoreDocs[0].doc);
     assertEquals(0, td.scoreDocs[1].doc);

Modified: lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCacheSortRandom.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCacheSortRandom.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCacheSortRandom.java (original)
+++ lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/uninverting/TestFieldCacheSortRandom.java Wed Jul 29 07:09:39 2015
@@ -168,14 +168,14 @@ public class TestFieldCacheSortRandom ex
       int queryType = random.nextInt(3);
       if (queryType == 0) {
         // force out of order
-        BooleanQuery bq = new BooleanQuery();
+        BooleanQuery.Builder bq = new BooleanQuery.Builder();
         // Add a Query with SHOULD, since bw.scorer() returns BooleanScorer2
         // which delegates to BS if there are no mandatory clauses.
         bq.add(new MatchAllDocsQuery(), Occur.SHOULD);
         // Set minNrShouldMatch to 1 so that BQ will not optimize rewrite to return
         // the clause instead of BQ.
         bq.setMinimumNumberShouldMatch(1);
-        hits = s.search(new FilteredQuery(bq, f), hitCount, sort, random.nextBoolean(), random.nextBoolean());
+        hits = s.search(new FilteredQuery(bq.build(), f), hitCount, sort, random.nextBoolean(), random.nextBoolean());
       } else if (queryType == 1) {
         hits = s.search(new ConstantScoreQuery(f),
                         hitCount, sort, random.nextBoolean(), random.nextBoolean());

Modified: lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java Wed Jul 29 07:09:39 2015
@@ -18,9 +18,13 @@ package org.apache.lucene.queries;
  */
 
 import java.io.IOException;
+import java.util.Objects;
+import java.util.Set;
 
-import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.Term;
 import org.apache.lucene.search.*;
+import org.apache.lucene.util.Bits;
 
 /**
  * The BoostingQuery class can be used to effectively demote results that match a given query. 
@@ -51,84 +55,91 @@ public class BoostingQuery extends Query
     }
 
     @Override
-    public Query rewrite(IndexReader reader) throws IOException {
-      BooleanQuery result = new BooleanQuery() {
+    public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
+      if (needsScores == false) {
+        return match.createWeight(searcher, needsScores);
+      }
+      final Weight matchWeight = match.createWeight(searcher, needsScores);
+      final Weight contextWeight = context.createWeight(searcher, false);
+      return new Weight(this) {
+
         @Override
-        public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
-          return new BooleanWeight(this, searcher, needsScores, false) {
+        public void extractTerms(Set<Term> terms) {
+          matchWeight.extractTerms(terms);
+          if (boost >= 1) {
+            contextWeight.extractTerms(terms);
+          }
+        }
 
-            @Override
-            public float coord(int overlap, int max) {
-              switch (overlap) {
+        @Override
+        public Explanation explain(LeafReaderContext context, int doc) throws IOException {
+          final Explanation matchExplanation = matchWeight.explain(context, doc);
+          final Explanation contextExplanation = contextWeight.explain(context, doc);
+          if (matchExplanation.isMatch() == false || contextExplanation.isMatch() == false) {
+            return matchExplanation;
+          }
+          return Explanation.match(matchExplanation.getValue() * boost, "product of:",
+              matchExplanation,
+              Explanation.match(boost, "boost"));
+        }
 
-              case 1:                               // matched only one clause
-                return 1.0f;                        // use the score as-is
+        @Override
+        public float getValueForNormalization() throws IOException {
+          return matchWeight.getValueForNormalization();
+        }
 
-              case 2:                               // matched both clauses
-                return boost;                       // multiply by boost
+        @Override
+        public void normalize(float norm, float topLevelBoost) {
+          matchWeight.normalize(norm, topLevelBoost);
+        }
 
-              default:
-                return 0.0f;
-                
+        @Override
+        public Scorer scorer(LeafReaderContext context) throws IOException {
+          final Scorer matchScorer = matchWeight.scorer(context);
+          if (matchScorer == null) {
+            return null;
+          }
+          final Scorer contextScorer = contextWeight.scorer(context);
+          if (contextScorer == null) {
+            return matchScorer;
+          }
+          final TwoPhaseIterator contextTwoPhase = contextScorer.asTwoPhaseIterator();
+          final DocIdSetIterator contextApproximation = contextTwoPhase == null
+              ? contextScorer
+              : contextTwoPhase.approximation();
+          return new FilterScorer(matchScorer) {
+            @Override
+            public float score() throws IOException {
+              if (contextApproximation.docID() < docID()) {
+                contextApproximation.advance(docID());
               }
+              assert contextApproximation.docID() >= docID();
+              float score = super.score();
+              if (contextApproximation.docID() == docID()
+                  && (contextTwoPhase == null || contextTwoPhase.matches())) {
+                score *= boost;
+              }
+              return score;
             }
           };
         }
       };
-
-      result.add(match, BooleanClause.Occur.MUST);
-      result.add(context, BooleanClause.Occur.SHOULD);
-
-      return result;
     }
 
     @Override
     public int hashCode() {
-      final int prime = 31;
-      int result = super.hashCode();
-      result = prime * result + Float.floatToIntBits(boost);
-      result = prime * result + ((context == null) ? 0 : context.hashCode());
-      result = prime * result + ((match == null) ? 0 : match.hashCode());
-      return result;
+      return 31 * super.hashCode() + Objects.hash(match, context, boost);
     }
 
     @Override
     public boolean equals(Object obj) {
-      if (this == obj) {
-        return true;
-      }
-      if (obj == null) {
-        return false;
-      }
-      if (getClass() != obj.getClass()) {
-        return false;
-      }
-      
-      if (!super.equals(obj)) {
-        return false;
-      }
-
-      BoostingQuery other = (BoostingQuery) obj;
-      if (Float.floatToIntBits(boost) != Float.floatToIntBits(other.boost)) {
-        return false;
-      }
-      
-      if (context == null) {
-        if (other.context != null) {
-          return false;
-        }
-      } else if (!context.equals(other.context)) {
-        return false;
-      }
-      
-      if (match == null) {
-        if (other.match != null) {
-          return false;
-        }
-      } else if (!match.equals(other.match)) {
+      if (super.equals(obj) == false) {
         return false;
       }
-      return true;
+      BoostingQuery that = (BoostingQuery) obj;
+      return match.equals(that.match)
+          && context.equals(that.context)
+          && Float.floatToIntBits(boost) == Float.floatToIntBits(that.boost);
     }
 
     @Override

Modified: lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/CommonTermsQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/CommonTermsQuery.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/CommonTermsQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/CommonTermsQuery.java Wed Jul 29 07:09:39 2015
@@ -16,25 +16,25 @@ package org.apache.lucene.queries;
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-import org.apache.lucene.index.LeafReaderContext;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.lucene.index.Fields;
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.index.Terms;
 import org.apache.lucene.index.TermsEnum;
-import org.apache.lucene.search.BooleanClause;
 import org.apache.lucene.search.BooleanClause.Occur;
 import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.MatchNoDocsQuery;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.similarities.Similarity;
 import org.apache.lucene.util.ToStringUtils;
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
 /**
  * A query that executes high-frequency terms in a optional sub-query to prevent
  * slow queries due to "common" terms like stopwords. This query
@@ -146,7 +146,7 @@ public class CommonTermsQuery extends Qu
   @Override
   public Query rewrite(IndexReader reader) throws IOException {
     if (this.terms.isEmpty()) {
-      return new BooleanQuery();
+      return new MatchNoDocsQuery();
     } else if (this.terms.size() == 1) {
       final Query tq = newTermQuery(this.terms.get(0), null);
       tq.setBoost(getBoost());
@@ -177,59 +177,72 @@ public class CommonTermsQuery extends Qu
   
   protected Query buildQuery(final int maxDoc,
       final TermContext[] contextArray, final Term[] queryTerms) {
-    BooleanQuery lowFreq = new BooleanQuery(disableCoord);
-    BooleanQuery highFreq = new BooleanQuery(disableCoord);
-    highFreq.setBoost(highFreqBoost);
-    lowFreq.setBoost(lowFreqBoost);
-    BooleanQuery query = new BooleanQuery(true);
+    List<Query> lowFreqQueries = new ArrayList<>();
+    List<Query> highFreqQueries = new ArrayList<>();
     for (int i = 0; i < queryTerms.length; i++) {
       TermContext termContext = contextArray[i];
       if (termContext == null) {
-        lowFreq.add(newTermQuery(queryTerms[i], null), lowFreqOccur);
+        lowFreqQueries.add(newTermQuery(queryTerms[i], null));
       } else {
         if ((maxTermFrequency >= 1f && termContext.docFreq() > maxTermFrequency)
             || (termContext.docFreq() > (int) Math.ceil(maxTermFrequency
                 * (float) maxDoc))) {
-          highFreq
-              .add(newTermQuery(queryTerms[i], termContext), highFreqOccur);
+          highFreqQueries
+              .add(newTermQuery(queryTerms[i], termContext));
         } else {
-          lowFreq.add(newTermQuery(queryTerms[i], termContext), lowFreqOccur);
+          lowFreqQueries.add(newTermQuery(queryTerms[i], termContext));
         }
       }
-      
     }
-    final int numLowFreqClauses = lowFreq.clauses().size();
-    final int numHighFreqClauses = highFreq.clauses().size();
+    final int numLowFreqClauses = lowFreqQueries.size();
+    final int numHighFreqClauses = highFreqQueries.size();
+    Occur lowFreqOccur = this.lowFreqOccur;
+    Occur highFreqOccur = this.highFreqOccur;
+    int lowFreqMinShouldMatch = 0;
+    int highFreqMinShouldMatch = 0;
     if (lowFreqOccur == Occur.SHOULD && numLowFreqClauses > 0) {
-      int minMustMatch = calcLowFreqMinimumNumberShouldMatch(numLowFreqClauses);
-      lowFreq.setMinimumNumberShouldMatch(minMustMatch);
+      lowFreqMinShouldMatch = calcLowFreqMinimumNumberShouldMatch(numLowFreqClauses);
     }
     if (highFreqOccur == Occur.SHOULD && numHighFreqClauses > 0) {
-      int minMustMatch = calcHighFreqMinimumNumberShouldMatch(numHighFreqClauses);
-      highFreq.setMinimumNumberShouldMatch(minMustMatch);
+      highFreqMinShouldMatch = calcHighFreqMinimumNumberShouldMatch(numHighFreqClauses);
     }
-    if (lowFreq.clauses().isEmpty()) {
+    if (lowFreqQueries.isEmpty()) {
       /*
        * if lowFreq is empty we rewrite the high freq terms in a conjunction to
        * prevent slow queries.
        */
-      if (highFreq.getMinimumNumberShouldMatch() == 0 && highFreqOccur != Occur.MUST) {
-        for (BooleanClause booleanClause : highFreq) {
-            booleanClause.setOccur(Occur.MUST);
-        }
+      if (highFreqMinShouldMatch == 0 && highFreqOccur != Occur.MUST) {
+        highFreqOccur = Occur.MUST;
       }
-      highFreq.setBoost(getBoost());
-      return highFreq;
-    } else if (highFreq.clauses().isEmpty()) {
-      // only do low freq terms - we don't have high freq terms
-      lowFreq.setBoost(getBoost());
-      return lowFreq;
-    } else {
-      query.add(highFreq, Occur.SHOULD);
-      query.add(lowFreq, Occur.MUST);
-      query.setBoost(getBoost());
-      return query;
     }
+    BooleanQuery.Builder builder = new BooleanQuery.Builder();
+    builder.setDisableCoord(true);
+
+    if (lowFreqQueries.isEmpty() == false) {
+      BooleanQuery.Builder lowFreq = new BooleanQuery.Builder();
+      lowFreq.setDisableCoord(disableCoord);
+      for (Query query : lowFreqQueries) {
+        lowFreq.add(query, lowFreqOccur);
+      }
+      lowFreq.setMinimumNumberShouldMatch(lowFreqMinShouldMatch);
+      Query lowFreqQuery = lowFreq.build();
+      lowFreqQuery.setBoost(lowFreqBoost);
+      builder.add(lowFreqQuery, Occur.MUST);
+    }
+    if (highFreqQueries.isEmpty() == false) {
+      BooleanQuery.Builder highFreq = new BooleanQuery.Builder();
+      highFreq.setDisableCoord(disableCoord);
+      for (Query query : highFreqQueries) {
+        highFreq.add(query, highFreqOccur);
+      }
+      highFreq.setMinimumNumberShouldMatch(highFreqMinShouldMatch);
+      Query highFreqQuery = highFreq.build();
+      highFreqQuery.setBoost(highFreqBoost);
+      builder.add(highFreqQuery, Occur.SHOULD);
+    }
+    Query rewritten = builder.build();
+    rewritten.setBoost(getBoost());
+    return rewritten;
   }
   
   public void collectTermContext(IndexReader reader,

Modified: lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java Wed Jul 29 07:09:39 2015
@@ -144,13 +144,12 @@ public class TermsQuery extends Query im
   public Query rewrite(IndexReader reader) throws IOException {
     final int threshold = Math.min(BOOLEAN_REWRITE_TERM_COUNT_THRESHOLD, BooleanQuery.getMaxClauseCount());
     if (termData.size() <= threshold) {
-      BooleanQuery bq = new BooleanQuery();
+      BooleanQuery.Builder bq = new BooleanQuery.Builder();
       TermIterator iterator = termData.iterator();
       for (BytesRef term = iterator.next(); term != null; term = iterator.next()) {
         bq.add(new TermQuery(new Term(iterator.field(), BytesRef.deepCopyOf(term))), Occur.SHOULD);
       }
-      assert bq.clauses().size() == termData.size();
-      ConstantScoreQuery csq = new ConstantScoreQuery(bq);
+      ConstantScoreQuery csq = new ConstantScoreQuery(bq.build());
       csq.setBoost(getBoost());
       return csq;
     }
@@ -303,13 +302,13 @@ public class TermsQuery extends Query im
         }
         if (matchingTerms != null) {
           assert builder == null;
-          BooleanQuery bq = new BooleanQuery();
+          BooleanQuery.Builder bq = new BooleanQuery.Builder();
           for (TermAndState t : matchingTerms) {
             final TermContext termContext = new TermContext(searcher.getTopReaderContext());
             termContext.register(t.state, context.ord, t.docFreq, t.totalTermFreq);
             bq.add(new TermQuery(new Term(t.field, t.term), termContext), Occur.SHOULD);
           }
-          Query q = new ConstantScoreQuery(bq);
+          Query q = new ConstantScoreQuery(bq.build());
           q.setBoost(score());
           return new WeightOrDocIdSet(searcher.rewrite(q).createWeight(searcher, needsScores));
         } else {

Modified: lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java Wed Jul 29 07:09:39 2015
@@ -613,7 +613,7 @@ public final class MoreLikeThis {
    * Create the More like query from a PriorityQueue
    */
   private Query createQuery(PriorityQueue<ScoreTerm> q) {
-    BooleanQuery query = new BooleanQuery();
+    BooleanQuery.Builder query = new BooleanQuery.Builder();
     ScoreTerm scoreTerm;
     float bestScore = -1;
 
@@ -635,7 +635,7 @@ public final class MoreLikeThis {
         break;
       }
     }
-    return query;
+    return query.build();
   }
 
   /**

Modified: lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThisQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThisQuery.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThisQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThisQuery.java Wed Jul 29 07:09:39 2015
@@ -71,10 +71,16 @@ public class MoreLikeThisQuery extends Q
     mlt.setMaxQueryTerms(maxQueryTerms);
     mlt.setStopWords(stopWords);
     BooleanQuery bq = (BooleanQuery) mlt.like(fieldName, new StringReader(likeText));
-    BooleanClause[] clauses = bq.getClauses();
+    BooleanQuery.Builder newBq = new BooleanQuery.Builder();
+    newBq.setDisableCoord(bq.isCoordDisabled());
+    for (BooleanClause clause : bq) {
+      newBq.add(clause);
+    }
     //make at least half the terms match
-    bq.setMinimumNumberShouldMatch((int) (clauses.length * percentTermsToMatch));
-    return bq;
+    newBq.setMinimumNumberShouldMatch((int) (bq.clauses().size() * percentTermsToMatch));
+    Query rewritten = newBq.build();
+    rewritten.setBoost(bq.getBoost());
+    return rewritten;
   }
 
   /* (non-Javadoc)

Modified: lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/CommonTermsQueryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/CommonTermsQueryTest.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/CommonTermsQueryTest.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/CommonTermsQueryTest.java Wed Jul 29 07:09:39 2015
@@ -453,7 +453,7 @@ public class CommonTermsQueryTest extend
       
       IndexSearcher searcher = newSearcher(reader);
       Occur lowFreqOccur = randomOccur(random());
-      BooleanQuery verifyQuery = new BooleanQuery();
+      BooleanQuery.Builder verifyQuery = new BooleanQuery.Builder();
       CommonTermsQuery cq = new CommonTermsQuery(randomOccur(random()),
           lowFreqOccur, highFreq - 1, random().nextBoolean());
       for (TermAndFreq termAndFreq : lowTerms) {
@@ -467,7 +467,7 @@ public class CommonTermsQueryTest extend
       
       TopDocs cqSearch = searcher.search(cq, reader.maxDoc());
       
-      TopDocs verifySearch = searcher.search(verifyQuery, reader.maxDoc());
+      TopDocs verifySearch = searcher.search(verifyQuery.build(), reader.maxDoc());
       assertEquals(verifySearch.totalHits, cqSearch.totalHits);
       Set<Integer> hits = new HashSet<>();
       for (ScoreDoc doc : verifySearch.scoreDocs) {

Modified: lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TermsFilterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TermsFilterTest.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TermsFilterTest.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TermsFilterTest.java Wed Jul 29 07:09:39 2015
@@ -232,11 +232,11 @@ public class TermsFilterTest extends Luc
       Collections.shuffle(terms, random());
       int numTerms = 1 + random().nextInt(
           Math.min(BooleanQuery.getMaxClauseCount(), terms.size()));
-      BooleanQuery bq = new BooleanQuery();
+      BooleanQuery.Builder bq = new BooleanQuery.Builder();
       for (int j = 0; j < numTerms; j++) {
         bq.add(new BooleanClause(new TermQuery(terms.get(j)), Occur.SHOULD));
       }
-      TopDocs queryResult = searcher.search(new ConstantScoreQuery(bq), reader.maxDoc());
+      TopDocs queryResult = searcher.search(new ConstantScoreQuery(bq.build()), reader.maxDoc());
       
       MatchAllDocsQuery matchAll = new MatchAllDocsQuery();
       final TermsFilter filter = termsFilter(singleField, terms.subList(0, numTerms));;

Modified: lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TermsQueryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TermsQueryTest.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TermsQueryTest.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TermsQueryTest.java Wed Jul 29 07:09:39 2015
@@ -101,11 +101,11 @@ public class TermsQueryTest extends Luce
         for (int j = 0; j < numQueryTerms; ++j) {
           queryTerms.add(allTerms.get(random().nextInt(allTerms.size())));
         }
-        final BooleanQuery bq = new BooleanQuery();
+        final BooleanQuery.Builder bq = new BooleanQuery.Builder();
         for (Term t : queryTerms) {
           bq.add(new TermQuery(t), Occur.SHOULD);
         }
-        final Query q1 = new ConstantScoreQuery(bq);
+        final Query q1 = new ConstantScoreQuery(bq.build());
         q1.setBoost(boost);
         final Query q2 = new TermsQuery(queryTerms);
         q2.setBoost(boost);

Modified: lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreExplanations.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreExplanations.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreExplanations.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreExplanations.java Wed Jul 29 07:09:39 2015
@@ -44,9 +44,10 @@ public class TestCustomScoreExplanations
   public void testTopLevelBoost() throws Exception {
     Query q = new TermQuery(new Term(FIELD, "w1"));
     CustomScoreQuery csq = new CustomScoreQuery(q, new FunctionQuery(new ConstValueSource(5)));
-    BooleanQuery bq = new BooleanQuery();
-    bq.add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
-    bq.add(csq, BooleanClause.Occur.MUST);
+    BooleanQuery.Builder bqB = new BooleanQuery.Builder();
+    bqB.add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
+    bqB.add(csq, BooleanClause.Occur.MUST);
+    BooleanQuery bq = bqB.build();
     bq.setBoost(6);
     qtest(bq, new int[] { 0,1,2,3 });
   }

Modified: lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreQuery.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/TestCustomScoreQuery.java Wed Jul 29 07:09:39 2015
@@ -174,12 +174,12 @@ public class TestCustomScoreQuery extend
 
   @Test
   public void testCustomExternalQuery() throws Exception {
-    BooleanQuery q1 = new BooleanQuery();
+    BooleanQuery.Builder q1 = new BooleanQuery.Builder();
     q1.add(new TermQuery(new Term(TEXT_FIELD, "first")), BooleanClause.Occur.SHOULD);
     q1.add(new TermQuery(new Term(TEXT_FIELD, "aid")), BooleanClause.Occur.SHOULD);
     q1.add(new TermQuery(new Term(TEXT_FIELD, "text")), BooleanClause.Occur.SHOULD);
     
-    final Query q = new CustomExternalQuery(q1);
+    final Query q = new CustomExternalQuery(q1.build());
     log(q);
 
     IndexReader r = DirectoryReader.open(dir);
@@ -225,20 +225,23 @@ public class TestCustomScoreQuery extend
     IndexSearcher s = newSearcher(r);
 
     // regular (boolean) query.
-    BooleanQuery q1 = new BooleanQuery();
-    q1.add(new TermQuery(new Term(TEXT_FIELD, "first")), BooleanClause.Occur.SHOULD);
-    q1.add(new TermQuery(new Term(TEXT_FIELD, "aid")), BooleanClause.Occur.SHOULD);
-    q1.add(new TermQuery(new Term(TEXT_FIELD, "text")), BooleanClause.Occur.SHOULD);
+    BooleanQuery.Builder q1b = new BooleanQuery.Builder();
+    q1b.add(new TermQuery(new Term(TEXT_FIELD, "first")), BooleanClause.Occur.SHOULD);
+    q1b.add(new TermQuery(new Term(TEXT_FIELD, "aid")), BooleanClause.Occur.SHOULD);
+    q1b.add(new TermQuery(new Term(TEXT_FIELD, "text")), BooleanClause.Occur.SHOULD);
+    Query q1 = q1b.build();
     log(q1);
 
     // custom query, that should score the same as q1.
-    BooleanQuery q2CustomNeutral = new BooleanQuery(true);
+    BooleanQuery.Builder q2CustomNeutralB = new BooleanQuery.Builder();
+    q2CustomNeutralB.setDisableCoord(true);
     Query q2CustomNeutralInner = new CustomScoreQuery(q1);
-    q2CustomNeutral.add(q2CustomNeutralInner, BooleanClause.Occur.SHOULD);
+    q2CustomNeutralInner.setBoost((float)Math.sqrt(dboost));
+    q2CustomNeutralB.add(q2CustomNeutralInner, BooleanClause.Occur.SHOULD);
     // a little tricky: we split the boost across an outer BQ and CustomScoreQuery
     // this ensures boosting is correct across all these functions (see LUCENE-4935)
+    Query q2CustomNeutral = q2CustomNeutralB.build();
     q2CustomNeutral.setBoost((float)Math.sqrt(dboost));
-    q2CustomNeutralInner.setBoost((float)Math.sqrt(dboost));
     log(q2CustomNeutral);
 
     // custom query, that should (by default) multiply the scores of q1 by that of the field

Modified: lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/mlt/TestMoreLikeThis.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/mlt/TestMoreLikeThis.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/mlt/TestMoreLikeThis.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/test/org/apache/lucene/queries/mlt/TestMoreLikeThis.java Wed Jul 29 07:09:39 2015
@@ -20,8 +20,8 @@ package org.apache.lucene.queries.mlt;
 import java.io.IOException;
 import java.io.StringReader;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
 import org.apache.lucene.analysis.Analyzer;
@@ -103,7 +103,7 @@ public class TestMoreLikeThis extends Lu
     
     BooleanQuery query = (BooleanQuery) mlt.like("text", new StringReader(
         "lucene release"));
-    List<BooleanClause> clauses = query.clauses();
+    Collection<BooleanClause> clauses = query.clauses();
     
     assertEquals("Expected " + originalValues.size() + " clauses.",
         originalValues.size(), clauses.size());
@@ -133,7 +133,7 @@ public class TestMoreLikeThis extends Lu
     mlt.setBoost(true);
     BooleanQuery query = (BooleanQuery) mlt.like("text", new StringReader(
         "lucene release"));
-    List<BooleanClause> clauses = query.clauses();
+    Collection<BooleanClause> clauses = query.clauses();
 
     for (BooleanClause clause : clauses) {
       TermQuery tq = (TermQuery) clause.getQuery();
@@ -169,7 +169,7 @@ public class TestMoreLikeThis extends Lu
     BooleanQuery query = (BooleanQuery) mlt.like("text",
         new StringReader("lucene"), new StringReader("lucene release"),
         new StringReader("apache"), new StringReader("apache lucene"));
-    List<BooleanClause> clauses = query.clauses();
+    Collection<BooleanClause> clauses = query.clauses();
     assertEquals("Expected 2 clauses only!", 2, clauses.size());
     for (BooleanClause clause : clauses) {
       Term term = ((TermQuery) clause.getQuery()).getTerm();
@@ -217,7 +217,7 @@ public class TestMoreLikeThis extends Lu
     BooleanQuery query = (BooleanQuery) mlt.like("text", new StringReader(likeText));
 
     // check best terms are topN of highest idf
-    List<BooleanClause> clauses = query.clauses();
+    Collection<BooleanClause> clauses = query.clauses();
     assertEquals("Expected" + topN + "clauses only!", topN, clauses.size());
 
     Term[] expectedTerms = new Term[topN];

Modified: lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/MultiFieldQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/MultiFieldQueryParser.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/MultiFieldQueryParser.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/MultiFieldQueryParser.java Wed Jul 29 07:09:39 2015
@@ -258,17 +258,17 @@ public class MultiFieldQueryParser exten
   public static Query parse(String[] queries, String[] fields, Analyzer analyzer) throws ParseException {
     if (queries.length != fields.length)
       throw new IllegalArgumentException("queries.length != fields.length");
-    BooleanQuery bQuery = new BooleanQuery();
+    BooleanQuery.Builder bQuery = new BooleanQuery.Builder();
     for (int i = 0; i < fields.length; i++)
     {
       QueryParser qp = new QueryParser(fields[i], analyzer);
       Query q = qp.parse(queries[i]);
       if (q!=null && // q never null, just being defensive
-          (!(q instanceof BooleanQuery) || ((BooleanQuery)q).getClauses().length>0)) {
+          (!(q instanceof BooleanQuery) || ((BooleanQuery)q).clauses().size()>0)) {
         bQuery.add(q, BooleanClause.Occur.SHOULD);
       }
     }
-    return bQuery;
+    return bQuery.build();
   }
 
   /**
@@ -306,16 +306,16 @@ public class MultiFieldQueryParser exten
       BooleanClause.Occur[] flags, Analyzer analyzer) throws ParseException {
     if (fields.length != flags.length)
       throw new IllegalArgumentException("fields.length != flags.length");
-    BooleanQuery bQuery = new BooleanQuery();
+    BooleanQuery.Builder bQuery = new BooleanQuery.Builder();
     for (int i = 0; i < fields.length; i++) {
       QueryParser qp = new QueryParser(fields[i], analyzer);
       Query q = qp.parse(query);
       if (q!=null && // q never null, just being defensive 
-          (!(q instanceof BooleanQuery) || ((BooleanQuery)q).getClauses().length>0)) {
+          (!(q instanceof BooleanQuery) || ((BooleanQuery)q).clauses().size()>0)) {
         bQuery.add(q, flags[i]);
       }
     }
-    return bQuery;
+    return bQuery.build();
   }
 
   /**
@@ -355,17 +355,17 @@ public class MultiFieldQueryParser exten
   {
     if (!(queries.length == fields.length && queries.length == flags.length))
       throw new IllegalArgumentException("queries, fields, and flags array have have different length");
-    BooleanQuery bQuery = new BooleanQuery();
+    BooleanQuery.Builder bQuery = new BooleanQuery.Builder();
     for (int i = 0; i < fields.length; i++)
     {
       QueryParser qp = new QueryParser(fields[i], analyzer);
       Query q = qp.parse(queries[i]);
       if (q!=null && // q never null, just being defensive
-          (!(q instanceof BooleanQuery) || ((BooleanQuery)q).getClauses().length>0)) {
+          (!(q instanceof BooleanQuery) || ((BooleanQuery)q).clauses().size()>0)) {
         bQuery.add(q, flags[i]);
       }
     }
-    return bQuery;
+    return bQuery.build();
   }
 
 }

Modified: lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserBase.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserBase.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserBase.java Wed Jul 29 07:09:39 2015
@@ -30,6 +30,7 @@ import org.apache.lucene.index.Term;
 import org.apache.lucene.queryparser.classic.QueryParser.Operator;
 import org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration;
 import org.apache.lucene.search.*;
+import org.apache.lucene.search.BooleanClause.Occur;
 import org.apache.lucene.search.BooleanQuery.TooManyClauses;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.QueryBuilder;
@@ -115,7 +116,7 @@ public abstract class QueryParserBase ex
     try {
       // TopLevelQuery is a Query followed by the end-of-input (EOF)
       Query res = TopLevelQuery(field);
-      return res!=null ? res : newBooleanQuery(false);
+      return res!=null ? res : newBooleanQuery(false).build();
     }
     catch (ParseException | TokenMgrError tme) {
       // rethrow to include the original query:
@@ -422,7 +423,7 @@ public abstract class QueryParserBase ex
     if (clauses.size() > 0 && conj == CONJ_AND) {
       BooleanClause c = clauses.get(clauses.size()-1);
       if (!c.isProhibited())
-        c.setOccur(BooleanClause.Occur.MUST);
+        clauses.set(clauses.size() - 1, new BooleanClause(c.getQuery(), Occur.MUST));
     }
 
     if (clauses.size() > 0 && operator == AND_OPERATOR && conj == CONJ_OR) {
@@ -432,7 +433,7 @@ public abstract class QueryParserBase ex
       // this modification a OR b would parsed as +a OR b
       BooleanClause c = clauses.get(clauses.size()-1);
       if (!c.isProhibited())
-        c.setOccur(BooleanClause.Occur.SHOULD);
+        clauses.set(clauses.size() - 1, new BooleanClause(c.getQuery(), Occur.SHOULD));
     }
 
     // We might have been passed a null query; the term might have been
@@ -711,11 +712,11 @@ public abstract class QueryParserBase ex
     if (clauses.size()==0) {
       return null; // all clause words were filtered away by the analyzer.
     }
-    BooleanQuery query = newBooleanQuery(disableCoord);
+    BooleanQuery.Builder query = newBooleanQuery(disableCoord);
     for(final BooleanClause clause: clauses) {
       query.add(clause);
     }
-    return query;
+    return query.build();
   }
 
   /**

Modified: lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/complexPhrase/ComplexPhraseQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/complexPhrase/ComplexPhraseQueryParser.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/complexPhrase/ComplexPhraseQueryParser.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/complexPhrase/ComplexPhraseQueryParser.java Wed Jul 29 07:09:39 2015
@@ -19,6 +19,7 @@ package org.apache.lucene.queryparser.co
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 
@@ -216,7 +217,7 @@ public class ComplexPhraseQueryParser ex
 
     private final boolean inOrder;
 
-    private Query contents;
+    private final Query[] contents = new Query[1];
 
     public ComplexPhraseQuery(String field, String phrasedQueryStringContents,
         int slopFactor, boolean inOrder) {
@@ -241,7 +242,7 @@ public class ComplexPhraseQueryParser ex
       try {
         //temporarily set the QueryParser to be parsing the default field for this phrase e.g author:"fred* smith"
         qp.field = this.field;
-        contents = qp.parse(phrasedQueryStringContents);
+        contents[0] = qp.parse(phrasedQueryStringContents);
       }
       finally {
         qp.field = oldDefaultParserField;
@@ -250,6 +251,7 @@ public class ComplexPhraseQueryParser ex
 
     @Override
     public Query rewrite(IndexReader reader) throws IOException {
+      final Query contents = this.contents[0];
       // ArrayList spanClauses = new ArrayList();
       if (contents instanceof TermQuery) {
         return contents;
@@ -265,15 +267,15 @@ public class ComplexPhraseQueryParser ex
             + "\"");
       }
       BooleanQuery bq = (BooleanQuery) contents;
-      BooleanClause[] bclauses = bq.getClauses();
-      SpanQuery[] allSpanClauses = new SpanQuery[bclauses.length];
+      SpanQuery[] allSpanClauses = new SpanQuery[bq.clauses().size()];
       // For all clauses e.g. one* two~
-      for (int i = 0; i < bclauses.length; i++) {
+      int i = 0;
+      for (BooleanClause clause : bq) {
         // HashSet bclauseterms=new HashSet();
-        Query qc = bclauses[i].getQuery();
+        Query qc = clause.getQuery();
         // Rewrite this clause e.g one* becomes (one OR onerous)
         qc = new IndexSearcher(reader).rewrite(qc);
-        if (bclauses[i].getOccur().equals(BooleanClause.Occur.MUST_NOT)) {
+        if (clause.getOccur().equals(BooleanClause.Occur.MUST_NOT)) {
           numNegatives++;
         }
 
@@ -301,6 +303,7 @@ public class ComplexPhraseQueryParser ex
           }
 
         }
+        i += 1;
       }
       if (numNegatives == 0) {
         // The simple case - no negative elements in phrase
@@ -310,10 +313,12 @@ public class ComplexPhraseQueryParser ex
       // sequence.
       // Need to return a SpanNotQuery
       ArrayList<SpanQuery> positiveClauses = new ArrayList<>();
-      for (int j = 0; j < allSpanClauses.length; j++) {
-        if (!bclauses[j].getOccur().equals(BooleanClause.Occur.MUST_NOT)) {
-          positiveClauses.add(allSpanClauses[j]);
+      i = 0;
+      for (BooleanClause clause : bq) {
+        if (!clause.getOccur().equals(BooleanClause.Occur.MUST_NOT)) {
+          positiveClauses.add(allSpanClauses[i]);
         }
+        i += 1;
       }
 
       SpanQuery[] includeClauses = positiveClauses
@@ -338,15 +343,14 @@ public class ComplexPhraseQueryParser ex
     private void addComplexPhraseClause(List<SpanQuery> spanClauses, BooleanQuery qc) {
       ArrayList<SpanQuery> ors = new ArrayList<>();
       ArrayList<SpanQuery> nots = new ArrayList<>();
-      BooleanClause[] bclauses = qc.getClauses();
 
       // For all clauses e.g. one* two~
-      for (int i = 0; i < bclauses.length; i++) {
-        Query childQuery = bclauses[i].getQuery();
+      for (BooleanClause clause : qc) {
+        Query childQuery = clause.getQuery();
 
         // select the list to which we will add these options
         ArrayList<SpanQuery> chosenList = ors;
-        if (bclauses[i].getOccur() == BooleanClause.Occur.MUST_NOT) {
+        if (clause.getOccur() == BooleanClause.Occur.MUST_NOT) {
           chosenList = nots;
         }
 

Modified: lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/QueryParserUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/QueryParserUtil.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/QueryParserUtil.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/QueryParserUtil.java Wed Jul 29 07:09:39 2015
@@ -54,7 +54,7 @@ final public class QueryParserUtil {
       throws QueryNodeException {
     if (queries.length != fields.length)
       throw new IllegalArgumentException("queries.length != fields.length");
-    BooleanQuery bQuery = new BooleanQuery();
+    BooleanQuery.Builder bQuery = new BooleanQuery.Builder();
 
     StandardQueryParser qp = new StandardQueryParser();
     qp.setAnalyzer(analyzer);
@@ -62,12 +62,11 @@ final public class QueryParserUtil {
     for (int i = 0; i < fields.length; i++) {
       Query q = qp.parse(queries[i], fields[i]);
 
-      if (q != null && // q never null, just being defensive
-          (!(q instanceof BooleanQuery) || ((BooleanQuery) q).getClauses().length > 0)) {
+      if (q != null) { // q never null, just being defensive
         bQuery.add(q, BooleanClause.Occur.SHOULD);
       }
     }
-    return bQuery;
+    return bQuery.build();
   }
 
   /**
@@ -110,7 +109,7 @@ final public class QueryParserUtil {
       BooleanClause.Occur[] flags, Analyzer analyzer) throws QueryNodeException {
     if (fields.length != flags.length)
       throw new IllegalArgumentException("fields.length != flags.length");
-    BooleanQuery bQuery = new BooleanQuery();
+    BooleanQuery.Builder bQuery = new BooleanQuery.Builder();
 
     StandardQueryParser qp = new StandardQueryParser();
     qp.setAnalyzer(analyzer);
@@ -118,12 +117,11 @@ final public class QueryParserUtil {
     for (int i = 0; i < fields.length; i++) {
       Query q = qp.parse(query, fields[i]);
 
-      if (q != null && // q never null, just being defensive
-          (!(q instanceof BooleanQuery) || ((BooleanQuery) q).getClauses().length > 0)) {
+      if (q != null) { // q never null, just being defensive
         bQuery.add(q, flags[i]);
       }
     }
-    return bQuery;
+    return bQuery.build();
   }
 
   /**
@@ -167,7 +165,7 @@ final public class QueryParserUtil {
     if (!(queries.length == fields.length && queries.length == flags.length))
       throw new IllegalArgumentException(
           "queries, fields, and flags array have have different length");
-    BooleanQuery bQuery = new BooleanQuery();
+    BooleanQuery.Builder bQuery = new BooleanQuery.Builder();
 
     StandardQueryParser qp = new StandardQueryParser();
     qp.setAnalyzer(analyzer);
@@ -175,12 +173,11 @@ final public class QueryParserUtil {
     for (int i = 0; i < fields.length; i++) {
       Query q = qp.parse(queries[i], fields[i]);
 
-      if (q != null && // q never null, just being defensive
-          (!(q instanceof BooleanQuery) || ((BooleanQuery) q).getClauses().length > 0)) {
+      if (q != null) { // q never null, just being defensive
         bQuery.add(q, flags[i]);
       }
     }
-    return bQuery;
+    return bQuery.build();
   }
 
   /**

Modified: lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/AnyQueryNodeBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/AnyQueryNodeBuilder.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/AnyQueryNodeBuilder.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/AnyQueryNodeBuilder.java Wed Jul 29 07:09:39 2015
@@ -44,7 +44,7 @@ public class AnyQueryNodeBuilder impleme
   public BooleanQuery build(QueryNode queryNode) throws QueryNodeException {
     AnyQueryNode andNode = (AnyQueryNode) queryNode;
 
-    BooleanQuery bQuery = new BooleanQuery();
+    BooleanQuery.Builder bQuery = new BooleanQuery.Builder();
     List<QueryNode> children = andNode.getChildren();
 
     if (children != null) {
@@ -75,7 +75,7 @@ public class AnyQueryNodeBuilder impleme
 
     bQuery.setMinimumNumberShouldMatch(andNode.getMinimumMatchingElements());
 
-    return bQuery;
+    return bQuery.build();
 
   }
 

Modified: lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/BooleanQueryNodeBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/BooleanQueryNodeBuilder.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/BooleanQueryNodeBuilder.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/BooleanQueryNodeBuilder.java Wed Jul 29 07:09:39 2015
@@ -51,7 +51,7 @@ public class BooleanQueryNodeBuilder imp
   public BooleanQuery build(QueryNode queryNode) throws QueryNodeException {
     BooleanQueryNode booleanNode = (BooleanQueryNode) queryNode;
 
-    BooleanQuery bQuery = new BooleanQuery();
+    BooleanQuery.Builder bQuery = new BooleanQuery.Builder();
     List<QueryNode> children = booleanNode.getChildren();
 
     if (children != null) {
@@ -80,7 +80,7 @@ public class BooleanQueryNodeBuilder imp
 
     }
 
-    return bQuery;
+    return bQuery.build();
 
   }
 

Modified: lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/MatchNoDocsQueryNodeBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/MatchNoDocsQueryNodeBuilder.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/MatchNoDocsQueryNodeBuilder.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/MatchNoDocsQueryNodeBuilder.java Wed Jul 29 07:09:39 2015
@@ -17,16 +17,16 @@ package org.apache.lucene.queryparser.fl
  * limitations under the License.
  */
 
-import org.apache.lucene.queryparser.flexible.messages.MessageImpl;
 import org.apache.lucene.queryparser.flexible.core.QueryNodeException;
 import org.apache.lucene.queryparser.flexible.core.messages.QueryParserMessages;
 import org.apache.lucene.queryparser.flexible.core.nodes.MatchNoDocsQueryNode;
 import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode;
+import org.apache.lucene.queryparser.flexible.messages.MessageImpl;
 import org.apache.lucene.queryparser.flexible.standard.parser.EscapeQuerySyntaxImpl;
-import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.MatchNoDocsQuery;
 
 /**
- * Builds an empty {@link BooleanQuery} object from a
+ * Builds a {@link MatchNoDocsQuery} object from a
  * {@link MatchNoDocsQueryNode} object.
  */
 public class MatchNoDocsQueryNodeBuilder implements StandardQueryBuilder {
@@ -36,7 +36,7 @@ public class MatchNoDocsQueryNodeBuilder
   }
 
   @Override
-  public BooleanQuery build(QueryNode queryNode) throws QueryNodeException {
+  public MatchNoDocsQuery build(QueryNode queryNode) throws QueryNodeException {
 
     // validates node
     if (!(queryNode instanceof MatchNoDocsQueryNode)) {
@@ -46,7 +46,7 @@ public class MatchNoDocsQueryNodeBuilder
               .getName()));
     }
 
-    return new BooleanQuery();
+    return new MatchNoDocsQuery();
 
   }
 

Modified: lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/StandardBooleanQueryNodeBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/StandardBooleanQueryNodeBuilder.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/StandardBooleanQueryNodeBuilder.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/builders/StandardBooleanQueryNodeBuilder.java Wed Jul 29 07:09:39 2015
@@ -53,7 +53,8 @@ public class StandardBooleanQueryNodeBui
   public BooleanQuery build(QueryNode queryNode) throws QueryNodeException {
     StandardBooleanQueryNode booleanNode = (StandardBooleanQueryNode) queryNode;
 
-    BooleanQuery bQuery = new BooleanQuery(booleanNode.isDisableCoord());
+    BooleanQuery.Builder bQuery = new BooleanQuery.Builder();
+    bQuery.setDisableCoord(booleanNode.isDisableCoord());
     List<QueryNode> children = booleanNode.getChildren();
 
     if (children != null) {
@@ -81,7 +82,7 @@ public class StandardBooleanQueryNodeBui
 
     }
 
-    return bQuery;
+    return bQuery.build();
 
   }
 

Modified: lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java?rev=1693190&r1=1693189&r2=1693190&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java Wed Jul 29 07:09:39 2015
@@ -414,6 +414,17 @@ public class SimpleQueryParser extends Q
     }
   }
 
+  private static BooleanQuery addClause(BooleanQuery bq, Query query, BooleanClause.Occur occur) {
+    BooleanQuery.Builder newBq = new BooleanQuery.Builder();
+    newBq.setDisableCoord(bq.isCoordDisabled());
+    newBq.setMinimumNumberShouldMatch(bq.getMinimumNumberShouldMatch());
+    for (BooleanClause clause : bq) {
+      newBq.add(clause);
+    }
+    newBq.add(query, occur);
+    return newBq.build();
+  }
+
   // buildQueryTree should be called after a term, phrase, or subquery
   // is consumed to be added to our existing query tree
   // this method will only add to the existing tree if the branch contained in state is not null
@@ -422,10 +433,10 @@ public class SimpleQueryParser extends Q
       // modify our branch to a BooleanQuery wrapper for not
       // this is necessary any time a term, phrase, or subquery is negated
       if (state.not % 2 == 1) {
-        BooleanQuery nq = new BooleanQuery();
+        BooleanQuery.Builder nq = new BooleanQuery.Builder();
         nq.add(branch, BooleanClause.Occur.MUST_NOT);
         nq.add(new MatchAllDocsQuery(), BooleanClause.Occur.SHOULD);
-        branch = nq;
+        branch = nq.build();
       }
 
       // first term (or phrase or subquery) found and will begin our query tree
@@ -443,13 +454,13 @@ public class SimpleQueryParser extends Q
         // because the previous operation must be evaluated separately to preserve
         // the proper precedence and the current operation will take over as the top of the tree
         if (state.previousOperation != state.currentOperation) {
-          BooleanQuery bq = new BooleanQuery();
+          BooleanQuery.Builder bq = new BooleanQuery.Builder();
           bq.add(state.top, state.currentOperation);
-          state.top = bq;
+          state.top = bq.build();
         }
 
         // reset all of the state for reuse
-        ((BooleanQuery)state.top).add(branch, state.currentOperation);
+        state.top = addClause((BooleanQuery) state.top, branch, state.currentOperation);
         state.previousOperation = state.currentOperation;
       }
 
@@ -518,7 +529,8 @@ public class SimpleQueryParser extends Q
    * Factory method to generate a standard query (no phrase or prefix operators).
    */
   protected Query newDefaultQuery(String text) {
-    BooleanQuery bq = new BooleanQuery(true);
+    BooleanQuery.Builder bq = new BooleanQuery.Builder();
+    bq.setDisableCoord(true);
     for (Map.Entry<String,Float> entry : weights.entrySet()) {
       Query q = createBooleanQuery(entry.getKey(), text, defaultOperator);
       if (q != null) {
@@ -526,14 +538,15 @@ public class SimpleQueryParser extends Q
         bq.add(q, BooleanClause.Occur.SHOULD);
       }
     }
-    return simplify(bq);
+    return simplify(bq.build());
   }
 
   /**
    * Factory method to generate a fuzzy query.
    */
   protected Query newFuzzyQuery(String text, int fuzziness) {
-    BooleanQuery bq = new BooleanQuery(true);
+    BooleanQuery.Builder bq = new BooleanQuery.Builder();
+    bq.setDisableCoord(true);
     for (Map.Entry<String,Float> entry : weights.entrySet()) {
       Query q = new FuzzyQuery(new Term(entry.getKey(), text), fuzziness);
       if (q != null) {
@@ -541,14 +554,15 @@ public class SimpleQueryParser extends Q
         bq.add(q, BooleanClause.Occur.SHOULD);
       }
     }
-    return simplify(bq);
+    return simplify(bq.build());
   }
 
   /**
    * Factory method to generate a phrase query with slop.
    */
   protected Query newPhraseQuery(String text, int slop) {
-    BooleanQuery bq = new BooleanQuery(true);
+    BooleanQuery.Builder bq = new BooleanQuery.Builder();
+    bq.setDisableCoord(true);
     for (Map.Entry<String,Float> entry : weights.entrySet()) {
       Query q = createPhraseQuery(entry.getKey(), text, slop);
       if (q != null) {
@@ -556,20 +570,21 @@ public class SimpleQueryParser extends Q
         bq.add(q, BooleanClause.Occur.SHOULD);
       }
     }
-    return simplify(bq);
+    return simplify(bq.build());
   }
 
   /**
    * Factory method to generate a prefix query.
    */
   protected Query newPrefixQuery(String text) {
-    BooleanQuery bq = new BooleanQuery(true);
+    BooleanQuery.Builder bq = new BooleanQuery.Builder();
+    bq.setDisableCoord(true);
     for (Map.Entry<String,Float> entry : weights.entrySet()) {
       PrefixQuery prefix = new PrefixQuery(new Term(entry.getKey(), text));
       prefix.setBoost(entry.getValue());
       bq.add(prefix, BooleanClause.Occur.SHOULD);
     }
-    return simplify(bq);
+    return simplify(bq.build());
   }
 
   /**
@@ -579,7 +594,7 @@ public class SimpleQueryParser extends Q
     if (bq.clauses().isEmpty()) {
       return null;
     } else if (bq.clauses().size() == 1) {
-      return bq.clauses().get(0).getQuery();
+      return bq.clauses().iterator().next().getQuery();
     } else {
       return bq;
     }