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/09/08 14:16:09 UTC

svn commit: r1701783 [3/6] - in /lucene/dev/branches/branch_5x: ./ lucene/ lucene/core/ lucene/core/src/java/org/apache/lucene/search/ lucene/core/src/java/org/apache/lucene/search/payloads/ lucene/core/src/java/org/apache/lucene/search/similarities/ l...

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestComplexExplanations.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestComplexExplanations.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestComplexExplanations.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestComplexExplanations.java Tue Sep  8 12:16:06 2015
@@ -71,12 +71,10 @@ public class TestComplexExplanations ext
 
     Query t = new FilteredQuery(new TermQuery(new Term(FIELD, "xx")),
                                 new QueryWrapperFilter(matchTheseItems(new int[] {1,3})));
-    t.setBoost(1000);
-    q.add(t, Occur.SHOULD);
+    q.add(new BoostQuery(t, 1000), Occur.SHOULD);
     
     t = new ConstantScoreQuery(matchTheseItems(new int[] {0,2}));
-    t.setBoost(30);
-    q.add(t, Occur.SHOULD);
+    q.add(new BoostQuery(t, 30), Occur.SHOULD);
     
     DisjunctionMaxQuery dm = new DisjunctionMaxQuery(0.2f);
     dm.add(snear(st("w2"),
@@ -131,12 +129,10 @@ public class TestComplexExplanations ext
     
     Query t = new FilteredQuery(new TermQuery(new Term(FIELD, "xx")),
                                 new QueryWrapperFilter(matchTheseItems(new int[] {1,3})));
-    t.setBoost(1000);
-    q.add(t, Occur.SHOULD);
+    q.add(new BoostQuery(t, 1000), Occur.SHOULD);
     
     t = new ConstantScoreQuery(matchTheseItems(new int[] {0,2}));
-    t.setBoost(-20.0f);
-    q.add(t, Occur.SHOULD);
+    q.add(new BoostQuery(t, -20), Occur.SHOULD);
     
     DisjunctionMaxQuery dm = new DisjunctionMaxQuery(0.2f);
     dm.add(snear(st("w2"),
@@ -171,9 +167,8 @@ public class TestComplexExplanations ext
     builder.add(snear("w2","w3",1,true), Occur.SHOULD);
     builder.add(snear("w1","w3",3,true), Occur.SHOULD);
     BooleanQuery b = builder.build(); 
-    b.setBoost(0.0f);
     
-    q.add(b, Occur.SHOULD);
+    q.add(new BoostQuery(b, 0), Occur.SHOULD);
     
     qtest(q.build(), new int[] { 0,1,2 });
   }
@@ -189,26 +184,22 @@ public class TestComplexExplanations ext
 
   public void testT3() throws Exception {
     TermQuery query = new TermQuery(new Term(FIELD, "w1"));
-    query.setBoost(0);
-    bqtest(query, new int[] { 0,1,2,3 });
+    bqtest(new BoostQuery(query, 0), new int[] { 0,1,2,3 });
   }
 
   public void testMA3() throws Exception {
     Query q=new MatchAllDocsQuery();
-    q.setBoost(0);
-    bqtest(q, new int[] { 0,1,2,3 });
+    bqtest(new BoostQuery(q, 0), new int[] { 0,1,2,3 });
   }
   
   public void testFQ5() throws Exception {
     TermQuery query = new TermQuery(new Term(FIELD, "xx"));
-    query.setBoost(0);
     bqtest(new FilteredQuery(query, new QueryWrapperFilter(matchTheseItems(new int[] {1,3}))), new int[] {3});
   }
   
   public void testCSQ4() throws Exception {
     Query q = new ConstantScoreQuery(matchTheseItems(new int[] {3}));
-    q.setBoost(0);
-    bqtest(q, new int[] {3});
+    bqtest(new BoostQuery(q, 0), new int[] {3});
   }
   
   public void testDMQ10() throws Exception {
@@ -217,17 +208,14 @@ public class TestComplexExplanations ext
     BooleanQuery.Builder query = new BooleanQuery.Builder();;
     query.add(new TermQuery(new Term(FIELD, "yy")), Occur.SHOULD);
     TermQuery boostedQuery = new TermQuery(new Term(FIELD, "w5"));
-    boostedQuery.setBoost(100);
-    query.add(boostedQuery, Occur.SHOULD);
+    query.add(new BoostQuery(boostedQuery, 100), Occur.SHOULD);
 
     q.add(query.build());
 
     TermQuery xxBoostedQuery = new TermQuery(new Term(FIELD, "xx"));
-    xxBoostedQuery.setBoost(0);
 
-    q.add(xxBoostedQuery);
-    q.setBoost(0.0f);
-    bqtest(q, new int[] { 0,2,3 });
+    q.add(new BoostQuery(xxBoostedQuery, 0));
+    bqtest(new BoostQuery(q, 0), new int[] { 0,2,3 });
   }
   
   public void testMPQ7() throws Exception {
@@ -235,8 +223,7 @@ public class TestComplexExplanations ext
     q.add(ta(new String[] {"w1"}));
     q.add(ta(new String[] {"w2"}));
     q.setSlop(1);
-    q.setBoost(0.0f);
-    bqtest(q, new int[] { 0,1,2 });
+    bqtest(new BoostQuery(q, 0), new int[] { 0,1,2 });
   }
   
   public void testBQ12() throws Exception {
@@ -244,8 +231,7 @@ public class TestComplexExplanations ext
     BooleanQuery.Builder query = new BooleanQuery.Builder();;
     query.add(new TermQuery(new Term(FIELD, "w1")), Occur.SHOULD);
     TermQuery boostedQuery = new TermQuery(new Term(FIELD, "w2"));
-    boostedQuery.setBoost(0);
-    query.add(boostedQuery, Occur.SHOULD);
+    query.add(new BoostQuery(boostedQuery, 0), Occur.SHOULD);
     
     qtest(query.build(), new int[] { 0,1,2,3 });
   }
@@ -254,8 +240,7 @@ public class TestComplexExplanations ext
     BooleanQuery.Builder query = new BooleanQuery.Builder();;
     query.add(new TermQuery(new Term(FIELD, "w1")), Occur.SHOULD);
     TermQuery boostedQuery = new TermQuery(new Term(FIELD, "w5"));
-    boostedQuery.setBoost(0);
-    query.add(boostedQuery, Occur.MUST_NOT);
+    query.add(new BoostQuery(boostedQuery, 0), Occur.MUST_NOT);
 
     qtest(query.build(), new int[] { 1,2,3 });
   }
@@ -263,8 +248,7 @@ public class TestComplexExplanations ext
     // NOTE: using qtest not bqtest
     BooleanQuery.Builder query = new BooleanQuery.Builder();;
     TermQuery boostedQuery = new TermQuery(new Term(FIELD, "w1"));
-    boostedQuery.setBoost(0);
-    query.add(boostedQuery, Occur.MUST);
+    query.add(new BoostQuery(boostedQuery, 0), Occur.MUST);
     query.add(new TermQuery(new Term(FIELD, "w2")), Occur.SHOULD);
     
     qtest(query.build(), new int[] { 0,1,2,3 });
@@ -275,66 +259,57 @@ public class TestComplexExplanations ext
     builder.add(new TermQuery(new Term(FIELD, "w2")), Occur.SHOULD);
 
     Query query = builder.build();
-    query.setBoost(0);
 
-    bqtest(query, new int[] { 0,1,2,3 });
+    bqtest(new BoostQuery(query, 0), new int[] { 0,1,2,3 });
   }
   public void testBQ22() throws Exception {
     BooleanQuery.Builder builder = new BooleanQuery.Builder();;
     TermQuery boostedQuery = new TermQuery(new Term(FIELD, "w1"));
-    boostedQuery.setBoost(0);
-    builder.add(boostedQuery, Occur.MUST);
+    builder.add(new BoostQuery(boostedQuery, 0), Occur.MUST);
     builder.add(new TermQuery(new Term(FIELD, "w2")), Occur.SHOULD);
     BooleanQuery query = builder.build();
-    query.setBoost(0);
 
-    bqtest(query, new int[] { 0,1,2,3 });
+    bqtest(new BoostQuery(query, 0), new int[] { 0,1,2,3 });
   }
 
   public void testST3() throws Exception {
     SpanQuery q = st("w1");
-    q.setBoost(0);
-    bqtest(q, new int[] {0,1,2,3});
+    bqtest(new SpanBoostQuery(q, 0), new int[] {0,1,2,3});
   }
   public void testST6() throws Exception {
     SpanQuery q = st("xx");
-    q.setBoost(0);
-    qtest(q, new int[] {2,3});
+    qtest(new SpanBoostQuery(q, 0), new int[] {2,3});
   }
 
   public void testSF3() throws Exception {
     SpanQuery q = sf(("w1"),1);
-    q.setBoost(0);
-    bqtest(q, new int[] {0,1,2,3});
+    bqtest(new SpanBoostQuery(q, 0), new int[] {0,1,2,3});
   }
   public void testSF7() throws Exception {
     SpanQuery q = sf(("xx"),3);
-    q.setBoost(0);
-    bqtest(q, new int[] {2,3});
+    bqtest(new SpanBoostQuery(q, 0), new int[] {2,3});
   }
   
   public void testSNot3() throws Exception {
     SpanQuery q = snot(sf("w1",10),st("QQ"));
-    q.setBoost(0);
-    bqtest(q, new int[] {0,1,2,3});
+    bqtest(new SpanBoostQuery(q, 0), new int[] {0,1,2,3});
   }
   public void testSNot6() throws Exception {
     SpanQuery q = snot(sf("w1",10),st("xx"));
-    q.setBoost(0);
-    bqtest(q, new int[] {0,1,2,3});
+    bqtest(new SpanBoostQuery(q, 0), new int[] {0,1,2,3});
   }
 
   public void testSNot8() throws Exception {
     // NOTE: using qtest not bqtest
     SpanQuery f = snear("w1","w3",10,true);
-    f.setBoost(0);
+    f = new SpanBoostQuery(f, 0);
     SpanQuery q = snot(f, st("xx"));
     qtest(q, new int[] {0,1,3});
   }
   public void testSNot9() throws Exception {
     // NOTE: using qtest not bqtest
     SpanQuery t = st("xx");
-    t.setBoost(0);
+    t = new SpanBoostQuery(t, 0);
     SpanQuery q = snot(snear("w1","w3",10,true), t);
     qtest(q, new int[] {0,1,3});
   }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestConjunctions.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestConjunctions.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestConjunctions.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestConjunctions.java Tue Sep  8 12:16:06 2015
@@ -94,7 +94,7 @@ public class TestConjunctions extends Lu
     }
 
     @Override
-    public SimWeight computeWeight(float queryBoost,
+    public SimWeight computeWeight(
         CollectionStatistics collectionStats, TermStatistics... termStats) {
       return new SimWeight() {
         @Override

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java Tue Sep  8 12:16:06 2015
@@ -109,17 +109,14 @@ public class TestConstantScoreQuery exte
         }
       });
       
-      final Query csq1 = new ConstantScoreQuery(new TermQuery(new Term ("field", "term")));
-      csq1.setBoost(2.0f);
-      final Query csq2 = new ConstantScoreQuery(csq1);
-      csq2.setBoost(5.0f);
+      final BoostQuery csq1 = new BoostQuery(new ConstantScoreQuery(new TermQuery(new Term ("field", "term"))), 2f);
+      final BoostQuery csq2 = new BoostQuery(new ConstantScoreQuery(csq1), 5f);
       
       final BooleanQuery.Builder bq = new BooleanQuery.Builder();
       bq.add(csq1, BooleanClause.Occur.SHOULD);
       bq.add(csq2, BooleanClause.Occur.SHOULD);
       
-      final Query csqbq = new ConstantScoreQuery(bq.build());
-      csqbq.setBoost(17.0f);
+      final BoostQuery csqbq = new BoostQuery(new ConstantScoreQuery(bq.build()), 17f);
       
       checkHits(searcher, csq1, csq1.getBoost(), TermScorer.class);
       checkHits(searcher, csq2, csq2.getBoost(), TermScorer.class);
@@ -203,16 +200,19 @@ public class TestConstantScoreQuery exte
     IndexReader r = w.getReader();
     w.close();
 
-    Filter filter = new QueryWrapperFilter(AssertingQuery.wrap(random(), new TermQuery(new Term("field", "a"))));
+    final Query wrapped = AssertingQuery.wrap(random(), new TermQuery(new Term("field", "a")));
+    Filter filter = new QueryWrapperFilter(wrapped);
     IndexSearcher s = newSearcher(r);
     assert s instanceof AssertingIndexSearcher;
     // this used to fail
     s.search(new ConstantScoreQuery(filter), new TotalHitCountCollector());
     
     // check the rewrite
-    Query rewritten = new ConstantScoreQuery(filter).rewrite(r);
-    assertTrue(rewritten instanceof ConstantScoreQuery);
-    assertTrue(((ConstantScoreQuery) rewritten).getQuery() instanceof AssertingQuery);
+    Query rewritten = filter;
+    for (Query q = rewritten.rewrite(r); q != rewritten; q = rewritten.rewrite(r)) {
+      rewritten = q;
+    }
+    assertEquals(new BoostQuery(new ConstantScoreQuery(wrapped), 0), rewritten);
     
     r.close();
     d.close();

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java Tue Sep  8 12:16:06 2015
@@ -516,8 +516,7 @@ public class TestDisjunctionMaxQuery ext
   /** macro */
   protected Query tq(String f, String t, float b) {
     Query q = tq(f, t);
-    q.setBoost(b);
-    return q;
+    return new BoostQuery(q, b);
   }
   
   protected void printHits(String test, ScoreDoc[] h, IndexSearcher searcher)

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestDocValuesScoring.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestDocValuesScoring.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestDocValuesScoring.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestDocValuesScoring.java Tue Sep  8 12:16:06 2015
@@ -153,8 +153,8 @@ public class TestDocValuesScoring extend
     }
 
     @Override
-    public SimWeight computeWeight(float queryBoost, CollectionStatistics collectionStats, TermStatistics... termStats) {
-      return sim.computeWeight(queryBoost, collectionStats, termStats);
+    public SimWeight computeWeight(CollectionStatistics collectionStats, TermStatistics... termStats) {
+      return sim.computeWeight(collectionStats, termStats);
     }
 
     @Override

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestElevationComparator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestElevationComparator.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestElevationComparator.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestElevationComparator.java Tue Sep  8 12:16:06 2015
@@ -121,8 +121,7 @@ public class TestElevationComparator ext
      // System.out.println(" pri doc=" + vals[i+1] + " pri=" + (1+max));
    }
    BooleanQuery q = b.build();
-   q.setBoost(0);
-   return q;
+   return new BoostQuery(q, 0f);
  }
 
  private Document adoc(String[] vals) {

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestFieldValueQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestFieldValueQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestFieldValueQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestFieldValueQuery.java Tue Sep  8 12:16:06 2015
@@ -139,15 +139,12 @@ public class TestFieldValueQuery extends
       iw.close();
 
       final float boost = random().nextFloat() * 10;
-      final Query ref = new ConstantScoreQuery(new TermQuery(new Term("has_value", "yes")));
-      ref.setBoost(boost);
+      final Query ref = new BoostQuery(new ConstantScoreQuery(new TermQuery(new Term("has_value", "yes"))), boost);
 
-      final Query q1 = new FieldValueQuery("dv1");
-      q1.setBoost(boost);
+      final Query q1 = new BoostQuery(new FieldValueQuery("dv1"), boost);
       assertSameMatches(searcher, ref, q1, true);
 
-      final Query q2 = new FieldValueQuery("dv2");
-      q2.setBoost(boost);
+      final Query q2 = new BoostQuery(new FieldValueQuery("dv2"), boost);
       assertSameMatches(searcher, ref, q2, true);
 
       reader.close();

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestFilteredQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestFilteredQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestFilteredQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestFilteredQuery.java Tue Sep  8 12:16:06 2015
@@ -217,6 +217,7 @@ public class TestFilteredQuery extends L
     assertEquals(hits1.length, hits2.length);
     
     for (int i = 0; i < hits1.length; i++) {
+      assertEquals(hits1[i].doc, hits2[i].doc);
       assertEquals(hits1[i].score, hits2[i].score, 0.000001f);
     }
   }
@@ -538,7 +539,6 @@ public class TestFilteredQuery extends L
     // QueryWrapperFilter has special rewrite rules
     FilteredQuery fq2 = new FilteredQuery(query, new QueryWrapperFilter(new MatchAllDocsQuery()));
     fq2.setBoost(fq.getBoost());
-    fq2.setBoost(42);
     assertEquals(searcher.search(fq, 1).scoreDocs[0].score, searcher.search(fq2, 1).scoreDocs[0].score, 10e-5);
     reader.close();
     dir.close();

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java Tue Sep  8 12:16:06 2015
@@ -241,16 +241,14 @@ public class TestLRUQueryCache extends L
     final IndexSearcher searcher = newSearcher(reader);
 
     final Query query1 = new TermQuery(new Term("color", "blue"));
-    query1.setBoost(random().nextFloat());
     // different instance yet equal
     final Query query2 = new TermQuery(new Term("color", "blue"));
-    query2.setBoost(random().nextFloat());
 
     final LRUQueryCache queryCache = new LRUQueryCache(Integer.MAX_VALUE, Long.MAX_VALUE);
     searcher.setQueryCache(queryCache);
     searcher.setQueryCachingPolicy(QueryCachingPolicy.ALWAYS_CACHE);
 
-    searcher.search(new ConstantScoreQuery(query1), 1);
+    searcher.search(new BoostQuery(new ConstantScoreQuery(query1), random().nextFloat()), 1);
     assertEquals(1, queryCache.cachedQueries().size());
 
     queryCache.clearQuery(query2);
@@ -472,8 +470,7 @@ public class TestLRUQueryCache extends L
 
     Query[] queries = new Query[10 + random().nextInt(10)];
     for (int i = 0; i < queries.length; ++i) {
-      queries[i] = new TermQuery(new Term("color", RandomPicks.randomFrom(random(), Arrays.asList("red", "blue", "green", "yellow"))));
-      queries[i].setBoost(random().nextFloat());
+      queries[i] = new BoostQuery(new TermQuery(new Term("color", RandomPicks.randomFrom(random(), Arrays.asList("red", "blue", "green", "yellow")))), random().nextFloat());
     }
 
     searcher.setQueryCache(queryCache);
@@ -481,10 +478,14 @@ public class TestLRUQueryCache extends L
     for (int i = 0; i < 20; ++i) {
       final int idx = random().nextInt(queries.length);
       searcher.search(new ConstantScoreQuery(queries[idx]), 1);
-      if (actualCounts.containsKey(queries[idx])) {
-        actualCounts.put(queries[idx], 1 + actualCounts.get(queries[idx]));
+      Query cacheKey = queries[idx];
+      while (cacheKey instanceof BoostQuery) {
+        cacheKey = ((BoostQuery) cacheKey).getQuery();
+      }
+      if (actualCounts.containsKey(cacheKey)) {
+        actualCounts.put(cacheKey, 1 + actualCounts.get(cacheKey));
       } else {
-        actualCounts.put(queries[idx], 1);
+        actualCounts.put(cacheKey, 1);
       }
     }
 
@@ -749,23 +750,10 @@ public class TestLRUQueryCache extends L
     dir2.close();
   }
 
-  private static Query cacheKey(Query query) {
-    if (query.getBoost() == 1f) {
-      return query;
-    } else {
-      Query key = query.clone();
-      key.setBoost(1f);
-      assert key == cacheKey(key);
-      return key;
-    }
-  }
-
   public void testUseRewrittenQueryAsCacheKey() throws IOException {
     final Query expectedCacheKey = new TermQuery(new Term("foo", "bar"));
     final BooleanQuery.Builder query = new BooleanQuery.Builder();
-    final Query sub = expectedCacheKey.clone();
-    sub.setBoost(42);
-    query.add(sub, Occur.MUST);
+    query.add(new BoostQuery(expectedCacheKey, 42f), Occur.MUST);
 
     final LRUQueryCache queryCache = new LRUQueryCache(1000000, 10000000);
     Directory dir = newDirectory();
@@ -782,13 +770,13 @@ public class TestLRUQueryCache extends L
 
       @Override
       public boolean shouldCache(Query query, LeafReaderContext context) throws IOException {
-        assertEquals(expectedCacheKey, cacheKey(query));
+        assertEquals(expectedCacheKey, query);
         return true;
       }
 
       @Override
       public void onUse(Query query) {
-        assertEquals(expectedCacheKey, cacheKey(query));
+        assertEquals(expectedCacheKey, query);
       }
     };
 

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java Tue Sep  8 12:16:06 2015
@@ -90,8 +90,6 @@ public class TestMatchAllDocsQuery exten
     Query q1 = new MatchAllDocsQuery();
     Query q2 = new MatchAllDocsQuery();
     assertTrue(q1.equals(q2));
-    q1.setBoost(1.5f);
-    assertFalse(q1.equals(q2));
   }
   
   private void addDoc(String text, IndexWriter iw, float boost) throws IOException {

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestMinShouldMatch2.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestMinShouldMatch2.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestMinShouldMatch2.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestMinShouldMatch2.java Tue Sep  8 12:16:06 2015
@@ -334,7 +334,7 @@ public class TestMinShouldMatch2 extends
           boolean success = ords.add(ord);
           assert success; // no dups
           TermContext context = TermContext.build(reader.getContext(), term);
-          SimWeight w = weight.similarity.computeWeight(1f, 
+          SimWeight w = weight.similarity.computeWeight(
                         searcher.collectionStatistics("field"),
                         searcher.termStatistics(term, context));
           w.getValueForNormalization(); // ignored

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java Tue Sep  8 12:16:06 2015
@@ -225,8 +225,7 @@ public class TestMultiTermConstantScore
     
     search.setSimilarity(new DefaultSimilarity());
     Query q = csrq("data", "1", "6", T, T);
-    q.setBoost(100);
-    search.search(q, new SimpleCollector() {
+    search.search(new BoostQuery(q, 100), new SimpleCollector() {
       private int base = 0;
       private Scorer scorer;
       @Override
@@ -252,8 +251,7 @@ public class TestMultiTermConstantScore
     // Ensure that boosting works to score one clause of a query higher
     // than another.
     //
-    Query q1 = csrq("data", "A", "A", T, T); // matches document #0
-    q1.setBoost(.1f);
+    Query q1 = new BoostQuery(csrq("data", "A", "A", T, T), .1f); // matches document #0
     Query q2 = csrq("data", "Z", "Z", T, T); // matches document #1
     BooleanQuery.Builder bq = new BooleanQuery.Builder();
     bq.setDisableCoord(true);
@@ -265,8 +263,7 @@ public class TestMultiTermConstantScore
     Assert.assertEquals(0, hits[1].doc);
     assertTrue(hits[0].score > hits[1].score);
 
-    q1 = csrq("data", "A", "A", T, T, MultiTermQuery.CONSTANT_SCORE_BOOLEAN_REWRITE); // matches document #0
-    q1.setBoost(.1f);
+    q1 = new BoostQuery(csrq("data", "A", "A", T, T, MultiTermQuery.CONSTANT_SCORE_BOOLEAN_REWRITE), .1f); // matches document #0
     q2 = csrq("data", "Z", "Z", T, T, MultiTermQuery.CONSTANT_SCORE_BOOLEAN_REWRITE); // matches document #1
     bq = new BooleanQuery.Builder();
     bq.setDisableCoord(true);
@@ -278,8 +275,7 @@ public class TestMultiTermConstantScore
     Assert.assertEquals(0, hits[1].doc);
     assertTrue(hits[0].score > hits[1].score);
 
-    q1 = csrq("data", "A", "A", T, T); // matches document #0
-    q1.setBoost(10f);
+    q1 = new BoostQuery(csrq("data", "A", "A", T, T), 10f); // matches document #0
     q2 = csrq("data", "Z", "Z", T, T); // matches document #1
     bq = new BooleanQuery.Builder();
     bq.add(q1, BooleanClause.Occur.SHOULD);

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestMultiTermQueryRewrites.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestMultiTermQueryRewrites.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestMultiTermQueryRewrites.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestMultiTermQueryRewrites.java Tue Sep  8 12:16:06 2015
@@ -143,9 +143,10 @@ public class TestMultiTermQueryRewrites
   
   private void checkBooleanQueryBoosts(BooleanQuery bq) {
     for (BooleanClause clause : bq.clauses()) {
-      final TermQuery mtq = (TermQuery) clause.getQuery();
+      final BoostQuery boostQ = (BoostQuery) clause.getQuery();
+      final TermQuery mtq = (TermQuery) boostQ.getQuery();
       assertEquals("Parallel sorting of boosts in rewrite mode broken",
-        Float.parseFloat(mtq.getTerm().text()), mtq.getBoost(), 0);
+        Float.parseFloat(mtq.getTerm().text()), boostQ.getBoost(), 0);
     }
   }
   

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestNGramPhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestNGramPhraseQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestNGramPhraseQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestNGramPhraseQuery.java Tue Sep  8 12:16:06 2015
@@ -76,14 +76,6 @@ public class TestNGramPhraseQuery extend
     PhraseQuery rewritten3 = (PhraseQuery) q;
     assertArrayEquals(new Term[]{new Term("f", "ABC"), new Term("f", "DEF"), new Term("f", "FGH")}, rewritten3.getTerms());
     assertArrayEquals(new int[]{0, 3, 5}, rewritten3.getPositions());
-    
-    // LUCENE-4970: boosting test
-    NGramPhraseQuery pq4 = new NGramPhraseQuery(2, new PhraseQuery("f", "AB", "BC", "CD"));
-    pq4.setBoost(100.0F);
-    
-    q = pq4.rewrite(reader);
-    assertNotSame(pq4, q);
-    assertEquals(pq4.getBoost(), q.getBoost(), 0.1f);
   }
 
 }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestNeedsScores.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestNeedsScores.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestNeedsScores.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestNeedsScores.java Tue Sep  8 12:16:06 2015
@@ -28,7 +28,6 @@ import org.apache.lucene.index.LeafReade
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.store.Directory;
-import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.LuceneTestCase;
 
@@ -144,7 +143,7 @@ public class TestNeedsScores extends Luc
     public Query rewrite(IndexReader reader) throws IOException {
       Query in2 = in.rewrite(reader);
       if (in2 == in) {
-        return this;
+        return super.rewrite(reader);
       } else {
         return new AssertNeedsScores(in2, value);
       }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java Tue Sep  8 12:16:06 2015
@@ -372,9 +372,6 @@ public class TestPhraseQuery extends Luc
     builder.setSlop(5);
     q = builder.build();
     assertEquals("field:\"? hi|hello ? ? ? test\"~5", q.toString());
-
-    q.setBoost(2);
-    assertEquals("field:\"? hi|hello ? ? ? test\"~5^2.0", q.toString());
   }
 
   public void testWrappedPhrase() throws IOException {

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java Tue Sep  8 12:16:06 2015
@@ -35,7 +35,6 @@ import org.apache.lucene.search.spans.Sp
 import org.apache.lucene.search.spans.SpanQuery;
 import org.apache.lucene.search.spans.SpanTermQuery;
 import org.apache.lucene.store.Directory;
-import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.TestUtil;
 

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestSimpleExplanations.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestSimpleExplanations.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestSimpleExplanations.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestSimpleExplanations.java Tue Sep  8 12:16:06 2015
@@ -36,8 +36,7 @@ public class TestSimpleExplanations exte
   }
   public void testT2() throws Exception {
     TermQuery termQuery = new TermQuery(new Term(FIELD, "w1"));
-    termQuery.setBoost(100);
-    qtest(termQuery, new int[] { 0,1,2,3 });
+    qtest(new BoostQuery(termQuery, 100), new int[] { 0,1,2,3 });
   }
   
   /* MatchAllDocs */
@@ -47,8 +46,7 @@ public class TestSimpleExplanations exte
   }
   public void testMA2() throws Exception {
     Query q=new MatchAllDocsQuery();
-    q.setBoost(1000);
-    qtest(q, new int[] { 0,1,2,3 });
+    qtest(new BoostQuery(q, 1000), new int[] { 0,1,2,3 });
   }
 
   /* some simple phrase tests */
@@ -124,8 +122,7 @@ public class TestSimpleExplanations exte
   }
   public void testCSQ3() throws Exception {
     Query q = new ConstantScoreQuery(matchTheseItems(new int[] {0,2}));
-    q.setBoost(1000);
-    qtest(q, new int[] {0,2});
+    qtest(new BoostQuery(q, 1000), new int[] {0,2});
   }
   
   /* DisjunctionMaxQuery */
@@ -194,13 +191,11 @@ public class TestSimpleExplanations exte
     booleanQuery.add(new TermQuery(new Term(FIELD, "yy")), BooleanClause.Occur.SHOULD);
 
     TermQuery boostedQuery = new TermQuery(new Term(FIELD, "w5"));
-    boostedQuery.setBoost(100);
-    booleanQuery.add(boostedQuery, BooleanClause.Occur.SHOULD);
+    booleanQuery.add(new BoostQuery(boostedQuery, 100), BooleanClause.Occur.SHOULD);
     q.add(booleanQuery.build());
 
     TermQuery xxBoostedQuery = new TermQuery(new Term(FIELD, "xx"));
-    xxBoostedQuery.setBoost(100000);
-    q.add(xxBoostedQuery);
+    q.add(new BoostQuery(xxBoostedQuery, 100000));
     
     qtest(q, new int[] { 0,2,3 });
   }
@@ -211,13 +206,11 @@ public class TestSimpleExplanations exte
     booleanQuery.add(new TermQuery(new Term(FIELD, "yy")), BooleanClause.Occur.SHOULD);
 
     TermQuery boostedQuery = new TermQuery(new Term(FIELD, "w5"));
-    boostedQuery.setBoost(100);
-    booleanQuery.add(boostedQuery, BooleanClause.Occur.SHOULD);
+    booleanQuery.add(new BoostQuery(boostedQuery, 100), BooleanClause.Occur.SHOULD);
     q.add(booleanQuery.build());
 
     TermQuery xxBoostedQuery = new TermQuery(new Term(FIELD, "xx"));
-    xxBoostedQuery.setBoost(0);
-    q.add(xxBoostedQuery);
+    q.add(new BoostQuery(xxBoostedQuery, 0));
 
     qtest(q, new int[] { 0,2,3 });
   }
@@ -404,8 +397,7 @@ public class TestSimpleExplanations exte
     BooleanQuery.Builder query = new BooleanQuery.Builder();
     query.add(new TermQuery(new Term(FIELD, "w1")), BooleanClause.Occur.SHOULD);
     TermQuery boostedQuery = new TermQuery(new Term(FIELD, "w1"));
-    boostedQuery.setBoost(1000);
-    query.add(boostedQuery, BooleanClause.Occur.SHOULD);
+    query.add(new BoostQuery(boostedQuery, 1000), BooleanClause.Occur.SHOULD);
 
     qtest(query.build(), new int[] { 0,1,2,3 });
   }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestSimpleSearchEquivalence.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestSimpleSearchEquivalence.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestSimpleSearchEquivalence.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestSimpleSearchEquivalence.java Tue Sep  8 12:16:06 2015
@@ -202,4 +202,32 @@ public class TestSimpleSearchEquivalence
     PhraseQuery q2 = builder.build();
     assertSameScores(q1, q2);
   }
+
+  public void testBoostQuerySimplification() throws Exception {
+    float b1 = random().nextFloat() * 10;
+    float b2 = random().nextFloat() * 10;
+    Term term = randomTerm();
+
+    Query q1 = new BoostQuery(new BoostQuery(new TermQuery(term), b2), b1);
+    // Use AssertingQuery to prevent BoostQuery from merging inner and outer boosts
+    Query q2 = new BoostQuery(new AssertingQuery(random(), new BoostQuery(new TermQuery(term), b2)), b1);
+
+    assertSameScores(q1, q2);
+  }
+
+  public void testBooleanBoostPropagation() throws Exception {
+    float boost1 = random().nextFloat();
+    Query tq = new BoostQuery(new TermQuery(randomTerm()), boost1);
+
+    float boost2 = random().nextFloat();
+    // Applying boost2 over the term or boolean query should have the same effect
+    Query q1 = new BoostQuery(tq, boost2);
+    Query q2 = new BooleanQuery.Builder()
+      .add(tq, Occur.MUST)
+      .add(tq, Occur.FILTER)
+      .build();
+    q2 = new BoostQuery(q2, boost2);
+
+    assertSameScores(q1, q2);
+  }
 }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestTermRangeQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestTermRangeQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestTermRangeQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestTermRangeQuery.java Tue Sep  8 12:16:06 2015
@@ -159,17 +159,12 @@ public class TestTermRangeQuery extends
   public void testEqualsHashcode() {
     Query query = TermRangeQuery.newStringRange("content", "A", "C", true, true);
     
-    query.setBoost(1.0f);
     Query other = TermRangeQuery.newStringRange("content", "A", "C", true, true);
-    other.setBoost(1.0f);
 
     assertEquals("query equals itself is true", query, query);
     assertEquals("equivalent queries are equal", query, other);
     assertEquals("hashcode must return same value when equals is true", query.hashCode(), other.hashCode());
 
-    other.setBoost(2.0f);
-    assertFalse("Different boost queries are not equal", query.equals(other));
-
     other = TermRangeQuery.newStringRange("notcontent", "A", "C", true, true);
     assertFalse("Different fields are not equal", query.equals(other));
 

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestTopFieldCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestTopFieldCollector.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestTopFieldCollector.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestTopFieldCollector.java Tue Sep  8 12:16:06 2015
@@ -190,11 +190,11 @@ public class TestTopFieldCollector exten
     text.setStringValue("baz");
     w.addDocument(doc);
     IndexReader reader = w.getReader();
-    TermQuery foo = new TermQuery(new Term("text", "foo"));
-    TermQuery bar = new TermQuery(new Term("text", "bar"));
-    bar.setBoost(2);
-    TermQuery baz = new TermQuery(new Term("text", "baz"));
-    baz.setBoost(3);
+    Query foo = new TermQuery(new Term("text", "foo"));
+    Query bar = new TermQuery(new Term("text", "bar"));
+    foo = new BoostQuery(foo, 2);
+    Query baz = new TermQuery(new Term("text", "baz"));
+    baz = new BoostQuery(baz, 3);
     Query query = new BooleanQuery.Builder()
         .add(foo, Occur.SHOULD)
         .add(bar, Occur.SHOULD)

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestUsageTrackingFilterCachingPolicy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestUsageTrackingFilterCachingPolicy.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestUsageTrackingFilterCachingPolicy.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestUsageTrackingFilterCachingPolicy.java Tue Sep  8 12:16:06 2015
@@ -30,19 +30,6 @@ public class TestUsageTrackingFilterCach
     assertFalse(UsageTrackingQueryCachingPolicy.isCostly(new TermQuery(new Term("field", "value"))));
   }
 
-  public void testBoostIgnored() {
-    Query q1 = new TermQuery(new Term("foo", "bar"));
-    q1.setBoost(2);
-    Query q2 = q1.clone();
-    q2.setBoost(3);
-    Query q3 = q1.clone();
-    q3.setBoost(4);
-    UsageTrackingQueryCachingPolicy policy = new UsageTrackingQueryCachingPolicy();
-    policy.onUse(q1);
-    policy.onUse(q2);
-    assertEquals(2, policy.frequency(q3));
-  }
-
   public void testNeverCacheMatchAll() throws Exception {
     Query q = new MatchAllDocsQuery();
     UsageTrackingQueryCachingPolicy policy = new UsageTrackingQueryCachingPolicy();

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestWildcard.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestWildcard.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestWildcard.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestWildcard.java Tue Sep  8 12:16:06 2015
@@ -70,22 +70,16 @@ public class TestWildcard extends Lucene
       assertMatches(searcher, wq, 1);
 
       wq.setRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_REWRITE);
-      wq.setBoost(0.1F);
       Query q = searcher.rewrite(wq);
       assertTrue(q instanceof TermQuery);
-      assertEquals(q.getBoost(), wq.getBoost(), 0);
       
       wq.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_REWRITE);
-      wq.setBoost(0.2F);
       q = searcher.rewrite(wq);
       assertTrue(q instanceof MultiTermQueryConstantScoreWrapper);
-      assertEquals(q.getBoost(), wq.getBoost(), 0.1);
       
       wq.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_REWRITE);
-      wq.setBoost(0.4F);
       q = searcher.rewrite(wq);
       assertTrue(q instanceof ConstantScoreQuery);
-      assertEquals(q.getBoost(), wq.getBoost(), 0.1);
       reader.close();
       indexStore.close();
   }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/payloads/TestPayloadExplanations.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/payloads/TestPayloadExplanations.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/payloads/TestPayloadExplanations.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/payloads/TestPayloadExplanations.java Tue Sep  8 12:16:06 2015
@@ -20,6 +20,7 @@ package org.apache.lucene.search.payload
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.BaseExplanationTestCase;
 import org.apache.lucene.search.similarities.DefaultSimilarity;
+import org.apache.lucene.search.spans.SpanBoostQuery;
 import org.apache.lucene.search.spans.SpanNearQuery;
 import org.apache.lucene.search.spans.SpanOrQuery;
 import org.apache.lucene.search.spans.SpanQuery;
@@ -65,8 +66,7 @@ public class TestPayloadExplanations ext
   public void testPT2() throws Exception {
     for (PayloadFunction fn : functions) {
       SpanQuery q = pt("w1", fn, false);
-      q.setBoost(1000);
-      qtest(q, new int[] {0,1,2,3});
+      qtest(new SpanBoostQuery(q, 1000), new int[] {0,1,2,3});
       q = pt("w1", fn, true);
       q.setBoost(1000);
       qtest(q, new int[] {0,1,2,3});
@@ -83,8 +83,7 @@ public class TestPayloadExplanations ext
   public void testPT5() throws Exception {
     for (PayloadFunction fn : functions) {
       SpanQuery q = pt("xx", fn, false);
-      q.setBoost(1000);
-      qtest(q, new int[] {2,3});
+      qtest(new SpanBoostQuery(q, 1000), new int[] {2,3});
       q = pt("xx", fn, true);
       q.setBoost(1000);
       qtest(q, new int[] {2,3});

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/similarities/TestSimilarityBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/similarities/TestSimilarityBase.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/similarities/TestSimilarityBase.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/similarities/TestSimilarityBase.java Tue Sep  8 12:16:06 2015
@@ -165,7 +165,7 @@ public class TestSimilarityBase extends
   
   /** Creates the default statistics object that the specific tests modify. */
   private BasicStats createStats() {
-    BasicStats stats = new BasicStats("spoof", 1);
+    BasicStats stats = new BasicStats("spoof");
     stats.setNumberOfDocuments(NUMBER_OF_DOCUMENTS);
     stats.setNumberOfFieldTokens(NUMBER_OF_FIELD_TOKENS);
     stats.setAvgFieldLength(AVG_FIELD_LENGTH);
@@ -189,9 +189,10 @@ public class TestSimilarityBase extends
    */
   private void unitTestCore(BasicStats stats, float freq, int docLen) {
     for (SimilarityBase sim : sims) {
-      BasicStats realStats = (BasicStats) sim.computeWeight(stats.getTotalBoost(),
+      BasicStats realStats = (BasicStats) sim.computeWeight(
           toCollectionStats(stats), 
           toTermStats(stats));
+      realStats.normalize(1f, stats.getBoost());
       float score = sim.score(realStats, freq, docLen);
       float explScore = sim.explain(
           realStats, 1, Explanation.match(freq, "freq"), docLen).getValue();
@@ -521,9 +522,10 @@ public class TestSimilarityBase extends
    */
   private void correctnessTestCore(SimilarityBase sim, float gold) {
     BasicStats stats = createStats();
-    BasicStats realStats = (BasicStats) sim.computeWeight(stats.getTotalBoost(),
+    BasicStats realStats = (BasicStats) sim.computeWeight(
         toCollectionStats(stats), 
         toTermStats(stats));
+    realStats.normalize(1f, stats.getBoost());
     float score = sim.score(realStats, FREQ, DOC_LEN);
     assertEquals(
         sim.toString() + " score not correct.", gold, score, FLOAT_EPSILON);

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestFieldMaskingSpanQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestFieldMaskingSpanQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestFieldMaskingSpanQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestFieldMaskingSpanQuery.java Tue Sep  8 12:16:06 2015
@@ -136,7 +136,6 @@ public class TestFieldMaskingSpanQuery e
   public void testRewrite0() throws Exception {
     SpanQuery q = new FieldMaskingSpanQuery
       (new SpanTermQuery(new Term("last", "sally")) , "first");
-    q.setBoost(8.7654321f);
     SpanQuery qr = (SpanQuery) searcher.rewrite(q);
 
     QueryUtils.checkEqual(q, qr);
@@ -195,16 +194,6 @@ public class TestFieldMaskingSpanQuery e
     QueryUtils.checkUnequal(q1, q3);
     QueryUtils.checkUnequal(q1, q4);
     QueryUtils.checkUnequal(q1, q5);
-    
-    SpanQuery qA = new FieldMaskingSpanQuery
-      (new SpanTermQuery(new Term("last", "sally")) , "first");
-    qA.setBoost(9f);
-    SpanQuery qB = new FieldMaskingSpanQuery
-      (new SpanTermQuery(new Term("last", "sally")) , "first");
-    QueryUtils.checkUnequal(qA, qB);
-    qB.setBoost(9f);
-    QueryUtils.checkEqual(qA, qB);
-    
   }
   
   public void testNoop0() throws Exception {

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanExplanations.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanExplanations.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanExplanations.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanExplanations.java Tue Sep  8 12:16:06 2015
@@ -19,8 +19,6 @@ package org.apache.lucene.search.spans;
 
 import org.apache.lucene.search.*;
 
-import static org.apache.lucene.search.spans.SpanTestUtil.*;
-
 /**
  * TestExplanations subclass focusing on span queries
  */
@@ -34,8 +32,7 @@ public class TestSpanExplanations extend
   }
   public void testST2() throws Exception {
     SpanQuery q = st("w1");
-    q.setBoost(1000);
-    qtest(q, new int[] {0,1,2,3});
+    qtest(new BoostQuery(q, 1000), new int[] {0,1,2,3});
   }
   public void testST4() throws Exception {
     SpanQuery q = st("xx");
@@ -43,8 +40,7 @@ public class TestSpanExplanations extend
   }
   public void testST5() throws Exception {
     SpanQuery q = st("xx");
-    q.setBoost(1000);
-    qtest(q, new int[] {2,3});
+    qtest(new BoostQuery(q, 1000), new int[] {2,3});
   }
 
   /* some SpanFirstQueries */
@@ -55,8 +51,7 @@ public class TestSpanExplanations extend
   }
   public void testSF2() throws Exception {
     SpanQuery q = sf(("w1"),1);
-    q.setBoost(1000);
-    qtest(q, new int[] {0,1,2,3});
+    qtest(new BoostQuery(q, 1000), new int[] {0,1,2,3});
   }
   public void testSF4() throws Exception {
     SpanQuery q = sf(("xx"),2);
@@ -68,8 +63,7 @@ public class TestSpanExplanations extend
   }
   public void testSF6() throws Exception {
     SpanQuery q = sf(("yy"),4);
-    q.setBoost(1000);
-    qtest(q, new int[] {2});
+    qtest(new BoostQuery(q, 1000), new int[] {2});
   }
   
   /* some SpanOrQueries */
@@ -150,8 +144,7 @@ public class TestSpanExplanations extend
   }
   public void testSNot2() throws Exception {
     SpanQuery q = snot(sf("w1",10),st("QQ"));
-    q.setBoost(1000);
-    qtest(q, new int[] {0,1,2,3});
+    qtest(new BoostQuery(q, 1000), new int[] {0,1,2,3});
   }
   public void testSNot4() throws Exception {
     SpanQuery q = snot(sf("w1",10),st("xx"));
@@ -159,18 +152,15 @@ public class TestSpanExplanations extend
   }
   public void testSNot5() throws Exception {
     SpanQuery q = snot(sf("w1",10),st("xx"));
-    q.setBoost(1000);
-    qtest(q, new int[] {0,1,2,3});
+    qtest(new BoostQuery(q, 1000), new int[] {0,1,2,3});
   }
   public void testSNot7() throws Exception {
     SpanQuery f = snear("w1","w3",10,true);
-    f.setBoost(1000);
     SpanQuery q = snot(f, st("xx"));
     qtest(q, new int[] {0,1,3});
   }
   public void testSNot10() throws Exception {
     SpanQuery t = st("xx");
-    t.setBoost(10000);
     SpanQuery q = snot(snear("w1","w3",10,true), t);
     qtest(q, new int[] {0,1,3});
   }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanSearchEquivalence.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanSearchEquivalence.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanSearchEquivalence.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanSearchEquivalence.java Tue Sep  8 12:16:06 2015
@@ -454,4 +454,16 @@ public class TestSpanSearchEquivalence e
     Query q2 = spanQuery(new SpanContainingQuery(nearQuery, termQuery));
     assertSameSet(q1, q2);
   }
+
+  public void testSpanBoostQuerySimplification() throws Exception {
+    float b1 = random().nextFloat() * 10;
+    float b2 = random().nextFloat() * 10;
+    Term term = randomTerm();
+
+    Query q1 = new SpanBoostQuery(new SpanBoostQuery(new SpanTermQuery(term), b2), b1);
+    // Use AssertingQuery to prevent BoostQuery from merging inner and outer boosts
+    Query q2 = new SpanBoostQuery(new AssertingSpanQuery(new SpanBoostQuery(new SpanTermQuery(term), b2)), b1);
+
+    assertSameScores(q1, q2);
+  }
 }

Modified: lucene/dev/branches/branch_5x/lucene/facet/src/java/org/apache/lucene/facet/DrillDownQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/facet/src/java/org/apache/lucene/facet/DrillDownQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/facet/src/java/org/apache/lucene/facet/DrillDownQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/facet/src/java/org/apache/lucene/facet/DrillDownQuery.java Tue Sep  8 12:16:06 2015
@@ -28,7 +28,7 @@ import org.apache.lucene.index.IndexRead
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.BooleanClause.Occur;
 import org.apache.lucene.search.BooleanQuery;
-import org.apache.lucene.search.ConstantScoreQuery;
+import org.apache.lucene.search.BoostQuery;
 import org.apache.lucene.search.MatchAllDocsQuery;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.TermQuery;
@@ -39,8 +39,8 @@ import org.apache.lucene.search.TermQuer
  * want to drill-down over.
  * <p>
  * <b>NOTE:</b> if you choose to create your own {@link Query} by calling
- * {@link #term}, it is recommended to wrap it with {@link ConstantScoreQuery}
- * and set the {@link ConstantScoreQuery#setBoost(float) boost} to {@code 0.0f},
+ * {@link #term}, it is recommended to wrap it in a {@link BoostQuery}
+ * with a boost of {@code 0.0f},
  * so that it does not affect the scores of the documents.
  * 
  * @lucene.experimental
@@ -138,6 +138,9 @@ public final class DrillDownQuery extend
   
   @Override
   public Query rewrite(IndexReader r) throws IOException {
+    if (getBoost() != 1f) {
+      return super.rewrite(r);
+    }
     BooleanQuery rewritten = getBooleanQuery();
     if (rewritten.clauses().isEmpty()) {
       return new MatchAllDocsQuery();

Modified: lucene/dev/branches/branch_5x/lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java Tue Sep  8 12:16:06 2015
@@ -63,6 +63,9 @@ class DrillSidewaysQuery extends Query {
 
   @Override
   public Query rewrite(IndexReader reader) throws IOException {
+    if (getBoost() != 1f) {
+      return super.rewrite(reader);
+    }
     Query newQuery = baseQuery;
     while(true) {
       Query rewrittenQuery = newQuery.rewrite(reader);
@@ -72,7 +75,7 @@ class DrillSidewaysQuery extends Query {
       newQuery = rewrittenQuery;
     }
     if (newQuery == baseQuery) {
-      return this;
+      return super.rewrite(reader);
     } else {
       return new DrillSidewaysQuery(newQuery, drillDownCollector, drillSidewaysCollectors, drillDownQueries, scoreSubDocsAtOnce);
     }
@@ -101,8 +104,8 @@ class DrillSidewaysQuery extends Query {
       }
 
       @Override
-      public void normalize(float norm, float topLevelBoost) {
-        baseWeight.normalize(norm, topLevelBoost);
+      public void normalize(float norm, float boost) {
+        baseWeight.normalize(norm, boost);
       }
 
       @Override

Modified: lucene/dev/branches/branch_5x/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRange.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRange.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRange.java (original)
+++ lucene/dev/branches/branch_5x/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRange.java Tue Sep  8 12:16:06 2015
@@ -140,12 +140,13 @@ public final class DoubleRange extends R
 
     @Override
     public Query rewrite(IndexReader reader) throws IOException {
+      if (getBoost() != 1f) {
+        return super.rewrite(reader);
+      }
       if (fastMatchQuery != null) {
         final Query fastMatchRewritten = fastMatchQuery.rewrite(reader);
         if (fastMatchRewritten != fastMatchQuery) {
-          Query rewritten = new ValueSourceQuery(range, fastMatchRewritten, valueSource);
-          rewritten.setBoost(getBoost());
-          return rewritten;
+          return new ValueSourceQuery(range, fastMatchRewritten, valueSource);
         }
       }
       return super.rewrite(reader);

Modified: lucene/dev/branches/branch_5x/lucene/facet/src/java/org/apache/lucene/facet/range/LongRange.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/facet/src/java/org/apache/lucene/facet/range/LongRange.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/facet/src/java/org/apache/lucene/facet/range/LongRange.java (original)
+++ lucene/dev/branches/branch_5x/lucene/facet/src/java/org/apache/lucene/facet/range/LongRange.java Tue Sep  8 12:16:06 2015
@@ -132,12 +132,13 @@ public final class LongRange extends Ran
 
     @Override
     public Query rewrite(IndexReader reader) throws IOException {
+      if (getBoost() != 1f) {
+        return super.rewrite(reader);
+      }
       if (fastMatchQuery != null) {
         final Query fastMatchRewritten = fastMatchQuery.rewrite(reader);
         if (fastMatchRewritten != fastMatchQuery) {
-          Query rewritten = new ValueSourceQuery(range, fastMatchRewritten, valueSource);
-          rewritten.setBoost(getBoost());
-          return rewritten;
+          return new ValueSourceQuery(range, fastMatchRewritten, valueSource);
         }
       }
       return super.rewrite(reader);

Modified: lucene/dev/branches/branch_5x/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java (original)
+++ lucene/dev/branches/branch_5x/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java Tue Sep  8 12:16:06 2015
@@ -56,7 +56,6 @@ import org.apache.lucene.queries.functio
 import org.apache.lucene.queries.function.valuesource.DoubleFieldSource;
 import org.apache.lucene.queries.function.valuesource.FloatFieldSource;
 import org.apache.lucene.queries.function.valuesource.LongFieldSource;
-import org.apache.lucene.search.DocIdSet;
 import org.apache.lucene.search.Explanation;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.MatchAllDocsQuery;
@@ -65,7 +64,6 @@ import org.apache.lucene.search.Query;
 import org.apache.lucene.search.Scorer;
 import org.apache.lucene.search.Weight;
 import org.apache.lucene.store.Directory;
-import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.TestUtil;
 
@@ -875,9 +873,7 @@ public class TestRangeFacetCounts extend
     public Query rewrite(IndexReader reader) throws IOException {
       final Query inRewritten = in.rewrite(reader);
       if (in != inRewritten) {
-        Query rewritten = new UsedQuery(inRewritten, used);
-        rewritten.setBoost(getBoost());
-        return rewritten;
+        return new UsedQuery(inRewritten, used);
       }
       return super.rewrite(reader);
     }

Modified: lucene/dev/branches/branch_5x/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java (original)
+++ lucene/dev/branches/branch_5x/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java Tue Sep  8 12:16:06 2015
@@ -51,6 +51,7 @@ import org.apache.lucene.queries.functio
 import org.apache.lucene.queries.function.valuesource.FloatFieldSource;
 import org.apache.lucene.queries.function.valuesource.IntFieldSource;
 import org.apache.lucene.queries.function.valuesource.LongFieldSource;
+import org.apache.lucene.search.BoostQuery;
 import org.apache.lucene.search.ConstantScoreQuery;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.MatchAllDocsQuery;
@@ -268,8 +269,7 @@ public class TestTaxonomyFacetSumValueSo
     DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoWriter);
     
     FacetsCollector fc = new FacetsCollector(true);
-    ConstantScoreQuery csq = new ConstantScoreQuery(new MatchAllDocsQuery());
-    csq.setBoost(2.0f);
+    BoostQuery csq = new BoostQuery(new ConstantScoreQuery(new MatchAllDocsQuery()), 2f);
     
     TopDocs td = FacetsCollector.search(newSearcher(r), csq, 10, fc);
 

Modified: lucene/dev/branches/branch_5x/lucene/highlighter/src/java/org/apache/lucene/search/highlight/QueryScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/highlighter/src/java/org/apache/lucene/search/highlight/QueryScorer.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/highlighter/src/java/org/apache/lucene/search/highlight/QueryScorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/highlighter/src/java/org/apache/lucene/search/highlight/QueryScorer.java Tue Sep  8 12:16:06 2015
@@ -216,10 +216,10 @@ public class QueryScorer implements Scor
     qse.setWrapIfNotCachingTokenFilter(wrapToCaching);
     qse.setUsePayloads(usePayloads);
     if (reader == null) {
-      this.fieldWeightedSpanTerms = qse.getWeightedSpanTerms(query,
+      this.fieldWeightedSpanTerms = qse.getWeightedSpanTerms(query, 1f,
           tokenStream, field);
     } else {
-      this.fieldWeightedSpanTerms = qse.getWeightedSpanTermsWithScores(query,
+      this.fieldWeightedSpanTerms = qse.getWeightedSpanTermsWithScores(query, 1f,
           tokenStream, field, reader);
     }
     if(qse.isCachedTokenStream()) {

Modified: lucene/dev/branches/branch_5x/lucene/highlighter/src/java/org/apache/lucene/search/highlight/QueryTermExtractor.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/highlighter/src/java/org/apache/lucene/search/highlight/QueryTermExtractor.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/highlighter/src/java/org/apache/lucene/search/highlight/QueryTermExtractor.java (original)
+++ lucene/dev/branches/branch_5x/lucene/highlighter/src/java/org/apache/lucene/search/highlight/QueryTermExtractor.java Tue Sep  8 12:16:06 2015
@@ -26,6 +26,7 @@ import org.apache.lucene.index.Term;
 import org.apache.lucene.search.BooleanClause;
 import org.apache.lucene.search.BooleanQuery;
 import org.apache.lucene.search.FilteredQuery;
+import org.apache.lucene.search.BoostQuery;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Query;
 
@@ -103,7 +104,7 @@ public final class QueryTermExtractor
   public static final WeightedTerm[] getTerms(Query query, boolean prohibited, String fieldName)
   {
     HashSet<WeightedTerm> terms=new HashSet<>();
-    getTerms(query,terms,prohibited,fieldName);
+    getTerms(query, 1f, terms,prohibited,fieldName);
     return terms.toArray(new WeightedTerm[0]);
   }
 
@@ -119,12 +120,15 @@ public final class QueryTermExtractor
       return getTerms(query,prohibited,null);
   }
 
-  private static final void getTerms(Query query, HashSet<WeightedTerm> terms, boolean prohibited, String fieldName) {
+  private static final void getTerms(Query query, float boost, HashSet<WeightedTerm> terms, boolean prohibited, String fieldName) {
     try {
-      if (query instanceof BooleanQuery)
-        getTermsFromBooleanQuery((BooleanQuery) query, terms, prohibited, fieldName);
+      if (query instanceof BoostQuery) {
+        BoostQuery boostQuery = (BoostQuery) query;
+        getTerms(boostQuery.getQuery(), boost * boostQuery.getBoost(), terms, prohibited, fieldName);
+      } else if (query instanceof BooleanQuery)
+        getTermsFromBooleanQuery((BooleanQuery) query, boost, terms, prohibited, fieldName);
       else if (query instanceof FilteredQuery)
-        getTermsFromFilteredQuery((FilteredQuery) query, terms, prohibited, fieldName);
+        getTermsFromFilteredQuery((FilteredQuery) query, boost, terms, prohibited, fieldName);
       else {
         HashSet<Term> nonWeightedTerms = new HashSet<>();
         try {
@@ -135,7 +139,7 @@ public final class QueryTermExtractor
         for (Iterator<Term> iter = nonWeightedTerms.iterator(); iter.hasNext(); ) {
           Term term = iter.next();
           if ((fieldName == null) || (term.field().equals(fieldName))) {
-            terms.add(new WeightedTerm(query.getBoost(), term.text()));
+            terms.add(new WeightedTerm(boost, term.text()));
           }
         }
       }
@@ -155,17 +159,18 @@ public final class QueryTermExtractor
    * something common which would allow access to child queries so what follows here are query-specific
    * implementations for accessing embedded query elements.
    */
-  private static final void getTermsFromBooleanQuery(BooleanQuery query, HashSet<WeightedTerm> terms, boolean prohibited, String fieldName)
+  private static final void getTermsFromBooleanQuery(BooleanQuery query, float boost, HashSet<WeightedTerm> terms, boolean prohibited, String fieldName)
   {
     for (BooleanClause clause : query)
     {
       if (prohibited || clause.getOccur()!=BooleanClause.Occur.MUST_NOT)
-        getTerms(clause.getQuery(), terms, prohibited, fieldName);
+        getTerms(clause.getQuery(), boost, terms, prohibited, fieldName);
     }
   }
-  private static void getTermsFromFilteredQuery(FilteredQuery query, HashSet<WeightedTerm> terms, boolean prohibited, String fieldName)
+
+  private static void getTermsFromFilteredQuery(FilteredQuery query, float boost, HashSet<WeightedTerm> terms, boolean prohibited, String fieldName)
   {
-    getTerms(query.getQuery(),terms,prohibited,fieldName);
+    getTerms(query.getQuery(), boost, terms,prohibited,fieldName);
   }
 
 }

Modified: lucene/dev/branches/branch_5x/lucene/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java (original)
+++ lucene/dev/branches/branch_5x/lucene/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java Tue Sep  8 12:16:06 2015
@@ -45,6 +45,7 @@ import org.apache.lucene.queries.CommonT
 import org.apache.lucene.queries.CustomScoreQuery;
 import org.apache.lucene.search.BooleanClause;
 import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.BoostQuery;
 import org.apache.lucene.search.ConstantScoreQuery;
 import org.apache.lucene.search.DisjunctionMaxQuery;
 import org.apache.lucene.search.FilteredQuery;
@@ -103,11 +104,14 @@ public class WeightedSpanTermExtractor {
    *          Map to place created WeightedSpanTerms in
    * @throws IOException If there is a low-level I/O error
    */
-  protected void extract(Query query, Map<String,WeightedSpanTerm> terms) throws IOException {
-    if (query instanceof BooleanQuery) {
+  protected void extract(Query query, float boost, Map<String,WeightedSpanTerm> terms) throws IOException {
+    if (query instanceof BoostQuery) {
+      BoostQuery boostQuery = (BoostQuery) query;
+      extract(boostQuery.getQuery(), boost * boostQuery.getBoost(), terms);
+    } else if (query instanceof BooleanQuery) {
       for (BooleanClause clause : (BooleanQuery) query) {
         if (!clause.isProhibited()) {
-          extract(clause.getQuery(), terms);
+          extract(clause.getQuery(), boost, terms);
         }
       }
     } else if (query instanceof PhraseQuery) {
@@ -144,31 +148,30 @@ public class WeightedSpanTermExtractor {
       }
 
       SpanNearQuery sp = new SpanNearQuery(clauses, slop, inorder);
-      sp.setBoost(query.getBoost());
-      extractWeightedSpanTerms(terms, sp);
+      extractWeightedSpanTerms(terms, sp, boost);
     } else if (query instanceof TermQuery) {
-      extractWeightedTerms(terms, query);
+      extractWeightedTerms(terms, query, boost);
     } else if (query instanceof SpanQuery) {
-      extractWeightedSpanTerms(terms, (SpanQuery) query);
+      extractWeightedSpanTerms(terms, (SpanQuery) query, boost);
     } else if (query instanceof FilteredQuery) {
-      extract(((FilteredQuery) query).getQuery(), terms);
+      extract(((FilteredQuery) query).getQuery(), boost, terms);
     } else if (query instanceof ConstantScoreQuery) {
       final Query q = ((ConstantScoreQuery) query).getQuery();
       if (q != null) {
-        extract(q, terms);
+        extract(q, boost, terms);
       }
     } else if (query instanceof CommonTermsQuery) {
       // specialized since rewriting would change the result query 
       // this query is TermContext sensitive.
-      extractWeightedTerms(terms, query);
+      extractWeightedTerms(terms, query, boost);
     } else if (query instanceof DisjunctionMaxQuery) {
       for (Iterator<Query> iterator = ((DisjunctionMaxQuery) query).iterator(); iterator.hasNext();) {
-        extract(iterator.next(), terms);
+        extract(iterator.next(), boost, terms);
       }
     } else if (query instanceof ToParentBlockJoinQuery) {
-      extract(((ToParentBlockJoinQuery) query).getChildQuery(), terms);
+      extract(((ToParentBlockJoinQuery) query).getChildQuery(), boost, terms);
     } else if (query instanceof ToChildBlockJoinQuery) {
-      extract(((ToChildBlockJoinQuery) query).getParentQuery(), terms);
+      extract(((ToChildBlockJoinQuery) query).getParentQuery(), boost, terms);
     } else if (query instanceof MultiPhraseQuery) {
       final MultiPhraseQuery mpq = (MultiPhraseQuery) query;
       final List<Term[]> termArrays = mpq.getTermArrays();
@@ -215,29 +218,28 @@ public class WeightedSpanTermExtractor {
         final boolean inorder = (slop == 0);
 
         SpanNearQuery sp = new SpanNearQuery(clauses, slop + positionGaps, inorder);
-        sp.setBoost(query.getBoost());
-        extractWeightedSpanTerms(terms, sp);
+        extractWeightedSpanTerms(terms, sp, boost);
       }
     } else if (query instanceof MatchAllDocsQuery) {
       //nothing
     } else if (query instanceof CustomScoreQuery){
-      extract(((CustomScoreQuery) query).getSubQuery(), terms);
+      extract(((CustomScoreQuery) query).getSubQuery(), boost, terms);
     } else {
       Query origQuery = query;
+      final IndexReader reader = getLeafContext().reader();
+      Query rewritten;
       if (query instanceof MultiTermQuery) {
         if (!expandMultiTermQuery) {
           return;
         }
-        MultiTermQuery copy = (MultiTermQuery) query.clone();
-        copy.setRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_REWRITE);
-        origQuery = copy;
+        rewritten = MultiTermQuery.SCORING_BOOLEAN_REWRITE.rewrite(reader, (MultiTermQuery) query);
+      } else {
+        rewritten = origQuery.rewrite(reader);
       }
-      final IndexReader reader = getLeafContext().reader();
-      Query rewritten = origQuery.rewrite(reader);
       if (rewritten != origQuery) {
         // only rewrite once and then flatten again - the rewritten query could have a speacial treatment
         // if this method is overwritten in a subclass or above in the next recursion
-        extract(rewritten, terms);
+        extract(rewritten, boost, terms);
       } 
     }
     extractUnknownQuery(query, terms);
@@ -258,7 +260,7 @@ public class WeightedSpanTermExtractor {
    *          SpanQuery to extract Terms from
    * @throws IOException If there is a low-level I/O error
    */
-  protected void extractWeightedSpanTerms(Map<String,WeightedSpanTerm> terms, SpanQuery spanQuery) throws IOException {
+  protected void extractWeightedSpanTerms(Map<String,WeightedSpanTerm> terms, SpanQuery spanQuery, float boost) throws IOException {
     Set<String> fieldNames;
 
     if (fieldName == null) {
@@ -328,7 +330,7 @@ public class WeightedSpanTermExtractor {
         WeightedSpanTerm weightedSpanTerm = terms.get(queryTerm.text());
 
         if (weightedSpanTerm == null) {
-          weightedSpanTerm = new WeightedSpanTerm(spanQuery.getBoost(), queryTerm.text());
+          weightedSpanTerm = new WeightedSpanTerm(boost, queryTerm.text());
           weightedSpanTerm.addPositionSpans(spanPositions);
           weightedSpanTerm.positionSensitive = true;
           terms.put(queryTerm.text(), weightedSpanTerm);
@@ -350,7 +352,7 @@ public class WeightedSpanTermExtractor {
    *          Query to extract Terms from
    * @throws IOException If there is a low-level I/O error
    */
-  protected void extractWeightedTerms(Map<String,WeightedSpanTerm> terms, Query query) throws IOException {
+  protected void extractWeightedTerms(Map<String,WeightedSpanTerm> terms, Query query, float boost) throws IOException {
     Set<Term> nonWeightedTerms = new HashSet<>();
     final IndexSearcher searcher = new IndexSearcher(getLeafContext());
     searcher.createNormalizedWeight(query, false).extractTerms(nonWeightedTerms);
@@ -358,7 +360,7 @@ public class WeightedSpanTermExtractor {
     for (final Term queryTerm : nonWeightedTerms) {
 
       if (fieldNameComparator(queryTerm.field())) {
-        WeightedSpanTerm weightedSpanTerm = new WeightedSpanTerm(query.getBoost(), queryTerm.text());
+        WeightedSpanTerm weightedSpanTerm = new WeightedSpanTerm(boost, queryTerm.text());
         terms.put(queryTerm.text(), weightedSpanTerm);
       }
     }
@@ -485,9 +487,9 @@ public class WeightedSpanTermExtractor {
    * @return Map containing WeightedSpanTerms
    * @throws IOException If there is a low-level I/O error
    */
-  public Map<String,WeightedSpanTerm> getWeightedSpanTerms(Query query, TokenStream tokenStream)
+  public Map<String,WeightedSpanTerm> getWeightedSpanTerms(Query query, float boost, TokenStream tokenStream)
       throws IOException {
-    return getWeightedSpanTerms(query, tokenStream, null);
+    return getWeightedSpanTerms(query, boost, tokenStream, null);
   }
 
   /**
@@ -504,7 +506,7 @@ public class WeightedSpanTermExtractor {
    * @return Map containing WeightedSpanTerms
    * @throws IOException If there is a low-level I/O error
    */
-  public Map<String,WeightedSpanTerm> getWeightedSpanTerms(Query query, TokenStream tokenStream,
+  public Map<String,WeightedSpanTerm> getWeightedSpanTerms(Query query, float boost, TokenStream tokenStream,
       String fieldName) throws IOException {
     if (fieldName != null) {
       this.fieldName = fieldName;
@@ -515,7 +517,7 @@ public class WeightedSpanTermExtractor {
     Map<String,WeightedSpanTerm> terms = new PositionCheckingMap<>();
     this.tokenStream = tokenStream;
     try {
-      extract(query, terms);
+      extract(query, boost, terms);
     } finally {
       IOUtils.close(internalReader);
     }
@@ -540,7 +542,7 @@ public class WeightedSpanTermExtractor {
    * @return Map of WeightedSpanTerms with quasi tf/idf scores
    * @throws IOException If there is a low-level I/O error
    */
-  public Map<String,WeightedSpanTerm> getWeightedSpanTermsWithScores(Query query, TokenStream tokenStream, String fieldName,
+  public Map<String,WeightedSpanTerm> getWeightedSpanTermsWithScores(Query query, float boost, TokenStream tokenStream, String fieldName,
       IndexReader reader) throws IOException {
     if (fieldName != null) {
       this.fieldName = fieldName;
@@ -550,7 +552,7 @@ public class WeightedSpanTermExtractor {
     this.tokenStream = tokenStream;
 
     Map<String,WeightedSpanTerm> terms = new PositionCheckingMap<>();
-    extract(query, terms);
+    extract(query, boost, terms);
 
     int totalNumDocs = reader.maxDoc();
     Set<String> weightedTerms = terms.keySet();

Modified: lucene/dev/branches/branch_5x/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldQuery.java?rev=1701783&r1=1701782&r2=1701783&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldQuery.java Tue Sep  8 12:16:06 2015
@@ -28,10 +28,10 @@ import java.util.Set;
 
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
-import org.apache.lucene.queries.CommonTermsQuery;
 import org.apache.lucene.queries.CustomScoreQuery;
 import org.apache.lucene.search.BooleanClause;
 import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.BoostQuery;
 import org.apache.lucene.search.ConstantScoreQuery;
 import org.apache.lucene.search.DisjunctionMaxQuery;
 import org.apache.lucene.search.FilteredQuery;
@@ -65,18 +65,24 @@ public class FieldQuery {
   FieldQuery( Query query, IndexReader reader, boolean phraseHighlight, boolean fieldMatch ) throws IOException {
     this.fieldMatch = fieldMatch;
     Set<Query> flatQueries = new LinkedHashSet<>();
-    flatten( query, reader, flatQueries );
+    flatten( query, reader, flatQueries, 1f );
     saveTerms( flatQueries, reader );
     Collection<Query> expandQueries = expand( flatQueries );
 
     for( Query flatQuery : expandQueries ){
       QueryPhraseMap rootMap = getRootMap( flatQuery );
       rootMap.add( flatQuery, reader );
+      float boost = 1f;
+      while (flatQuery instanceof BoostQuery) {
+        BoostQuery bq = (BoostQuery) flatQuery;
+        flatQuery = bq.getQuery();
+        boost *= bq.getBoost();
+      }
       if( !phraseHighlight && flatQuery instanceof PhraseQuery ){
         PhraseQuery pq = (PhraseQuery)flatQuery;
         if( pq.getTerms().length > 1 ){
           for( Term term : pq.getTerms() )
-            rootMap.addTerm( term, flatQuery.getBoost() );
+            rootMap.addTerm( term, boost );
         }
       }
     }
@@ -89,80 +95,73 @@ public class FieldQuery {
     this (query, null, phraseHighlight, fieldMatch);
   }
 
-  void flatten( Query sourceQuery, IndexReader reader, Collection<Query> flatQueries ) throws IOException{
+  void flatten( Query sourceQuery, IndexReader reader, Collection<Query> flatQueries, float boost ) throws IOException{
+    while (sourceQuery instanceof BoostQuery) {
+      BoostQuery bq = (BoostQuery) sourceQuery;
+      sourceQuery = bq.getQuery();
+      boost *= bq.getBoost();
+    }
     if( sourceQuery instanceof BooleanQuery ){
       BooleanQuery bq = (BooleanQuery)sourceQuery;
       for( BooleanClause clause : bq ) {
         if( !clause.isProhibited() ) {
-          flatten( applyParentBoost( clause.getQuery(), bq ), reader, flatQueries );
+          flatten( clause.getQuery(), reader, flatQueries, boost );
         }
       }
     } else if( sourceQuery instanceof DisjunctionMaxQuery ){
       DisjunctionMaxQuery dmq = (DisjunctionMaxQuery)sourceQuery;
       for( Query query : dmq ){
-        flatten( applyParentBoost( query, dmq ), reader, flatQueries );
+        flatten( query, reader, flatQueries, boost );
       }
     }
     else if( sourceQuery instanceof TermQuery ){
+      if (boost != 1f) {
+        sourceQuery = new BoostQuery(sourceQuery, boost);
+      }
       if( !flatQueries.contains( sourceQuery ) )
         flatQueries.add( sourceQuery );
     }
     else if( sourceQuery instanceof PhraseQuery ){
-      if( !flatQueries.contains( sourceQuery ) ){
-        PhraseQuery pq = (PhraseQuery)sourceQuery;
-        if( pq.getTerms().length > 1 )
-          flatQueries.add( pq );
-        else if( pq.getTerms().length == 1 ){
-          Query flat = new TermQuery( pq.getTerms()[0] );
-          flat.setBoost( pq.getBoost() );
-          flatQueries.add( flat );
-        }
+      PhraseQuery pq = (PhraseQuery)sourceQuery;
+      if( pq.getTerms().length == 1 )
+        sourceQuery = new TermQuery( pq.getTerms()[0] );
+      if (boost != 1f) {
+        sourceQuery = new BoostQuery(sourceQuery, boost);
       }
+      flatQueries.add(sourceQuery);
     } else if (sourceQuery instanceof ConstantScoreQuery) {
       final Query q = ((ConstantScoreQuery) sourceQuery).getQuery();
       if (q != null) {
-        flatten( applyParentBoost( q, sourceQuery ), reader, flatQueries);
+        flatten( q, reader, flatQueries, boost);
       }
     } else if (sourceQuery instanceof FilteredQuery) {
       final Query q = ((FilteredQuery) sourceQuery).getQuery();
       if (q != null) {
-        flatten( applyParentBoost( q, sourceQuery ), reader, flatQueries);
+        flatten( q, reader, flatQueries, boost);
       }
     } else if (sourceQuery instanceof CustomScoreQuery) {
       final Query q = ((CustomScoreQuery) sourceQuery).getSubQuery();
       if (q != null) {
-        flatten( applyParentBoost( q, sourceQuery ), reader, flatQueries);
+        flatten( q, reader, flatQueries, boost);
       }
     } else if (reader != null) {
       Query query = sourceQuery;
+      Query rewritten;
       if (sourceQuery instanceof MultiTermQuery) {
-        MultiTermQuery copy = (MultiTermQuery) sourceQuery.clone();
-        copy.setRewriteMethod(new MultiTermQuery.TopTermsScoringBooleanQueryRewrite(MAX_MTQ_TERMS));
-        query = copy;
+        rewritten = new MultiTermQuery.TopTermsScoringBooleanQueryRewrite(MAX_MTQ_TERMS).rewrite(reader, (MultiTermQuery) query);
+      } else {
+        rewritten = query.rewrite(reader);
       }
-      Query rewritten = query.rewrite(reader);
       if (rewritten != query) {
         // only rewrite once and then flatten again - the rewritten query could have a speacial treatment
         // if this method is overwritten in a subclass.
-        flatten(rewritten, reader, flatQueries);
+        flatten(rewritten, reader, flatQueries, boost);
         
       } 
       // if the query is already rewritten we discard it
     }
     // else discard queries
   }
-
-  /**
-   * Push parent's boost into a clone of query if parent has a non 1 boost.
-   */
-  protected Query applyParentBoost( Query query, Query parent ) {
-    if ( parent.getBoost() == 1 ) {
-      return query;
-    }
-    Query cloned = query.clone();
-    cloned.setBoost( query.getBoost() * parent.getBoost() );
-    return cloned;
-  }
   
   /*
    * Create expandQueries from flatQueries.
@@ -180,11 +179,23 @@ public class FieldQuery {
       Query query = i.next();
       i.remove();
       expandQueries.add( query );
+      float queryBoost = 1f;
+      while (query instanceof BoostQuery) {
+        BoostQuery bq = (BoostQuery) query;
+        queryBoost *= bq.getBoost();
+        query = bq.getQuery();
+      }
       if( !( query instanceof PhraseQuery ) ) continue;
       for( Iterator<Query> j = flatQueries.iterator(); j.hasNext(); ){
         Query qj = j.next();
+        float qjBoost = 1f;
+        while (qj instanceof BoostQuery) {
+          BoostQuery bq = (BoostQuery) qj;
+          qjBoost *= bq.getBoost();
+          qj = bq.getQuery();
+        }
         if( !( qj instanceof PhraseQuery ) ) continue;
-        checkOverlap( expandQueries, (PhraseQuery)query, (PhraseQuery)qj );
+        checkOverlap( expandQueries, (PhraseQuery)query, queryBoost, (PhraseQuery)qj, qjBoost );
       }
     }
     return expandQueries;
@@ -197,13 +208,13 @@ public class FieldQuery {
    * ex2) A="b c", B="a b" => overlap; expandQueries={"a b c"}
    * ex3) A="a b", B="c d" => no overlap; expandQueries={}
    */
-  private void checkOverlap( Collection<Query> expandQueries, PhraseQuery a, PhraseQuery b ){
+  private void checkOverlap( Collection<Query> expandQueries, PhraseQuery a, float aBoost, PhraseQuery b, float bBoost ){
     if( a.getSlop() != b.getSlop() ) return;
     Term[] ats = a.getTerms();
     Term[] bts = b.getTerms();
     if( fieldMatch && !ats[0].field().equals( bts[0].field() ) ) return;
-    checkOverlap( expandQueries, ats, bts, a.getSlop(), a.getBoost() );
-    checkOverlap( expandQueries, bts, ats, b.getSlop(), b.getBoost() );
+    checkOverlap( expandQueries, ats, bts, a.getSlop(), aBoost);
+    checkOverlap( expandQueries, bts, ats, b.getSlop(), bBoost );
   }
 
   /*
@@ -239,8 +250,10 @@ public class FieldQuery {
           pqBuilder.add( new Term( src[0].field(), dest[k].text() ) );
         }
         pqBuilder.setSlop( slop );
-        PhraseQuery pq = pqBuilder.build();
-        pq.setBoost( boost );
+        Query pq = pqBuilder.build();
+        if (boost != 1f) {
+          pq = new BoostQuery(pq, 1f);
+        }
         if(!expandQueries.contains( pq ) )
           expandQueries.add( pq );
       }
@@ -263,6 +276,9 @@ public class FieldQuery {
    */
   private String getKey( Query query ){
     if( !fieldMatch ) return null;
+    while (query instanceof BoostQuery) {
+      query = ((BoostQuery) query).getQuery();
+    }
     if( query instanceof TermQuery )
       return ((TermQuery)query).getTerm().field();
     else if ( query instanceof PhraseQuery ){
@@ -299,8 +315,11 @@ public class FieldQuery {
    *      - fieldMatch==false
    *          termSetMap=Map<null,Set<"john","lennon">>
    */
-    void saveTerms( Collection<Query> flatQueries, IndexReader reader ) throws IOException{
+  void saveTerms( Collection<Query> flatQueries, IndexReader reader ) throws IOException{
     for( Query query : flatQueries ){
+      while (query instanceof BoostQuery) {
+        query = ((BoostQuery) query).getQuery();
+      }
       Set<String> termSet = getTermSet( query );
       if( query instanceof TermQuery )
         termSet.add( ((TermQuery)query).getTerm().text() );
@@ -391,9 +410,15 @@ public class FieldQuery {
       return map;
     }
 
-      void add( Query query, IndexReader reader ) {
+    void add( Query query, IndexReader reader ) {
+      float boost = 1f;
+      while (query instanceof BoostQuery) {
+        BoostQuery bq = (BoostQuery) query;
+        query = bq.getQuery();
+        boost = bq.getBoost();
+      }
       if( query instanceof TermQuery ){
-        addTerm( ((TermQuery)query).getTerm(), query.getBoost() );
+        addTerm( ((TermQuery)query).getTerm(), boost );
       }
       else if( query instanceof PhraseQuery ){
         PhraseQuery pq = (PhraseQuery)query;
@@ -404,7 +429,7 @@ public class FieldQuery {
           qpm = getOrNewMap( map, term.text() );
           map = qpm.subMap;
         }
-        qpm.markTerminal( pq.getSlop(), pq.getBoost() );
+        qpm.markTerminal( pq.getSlop(), boost );
       }
       else
         throw new RuntimeException( "query \"" + query.toString() + "\" must be flatten first." );