lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpou...@apache.org
Subject svn commit: r1674100 [1/2] - 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/spans/ lucene/c...
Date Thu, 16 Apr 2015 15:56:14 GMT
Author: jpountz
Date: Thu Apr 16 15:56:13 2015
New Revision: 1674100

URL: http://svn.apache.org/r1674100
Log:
LUCENE-6425: Replaced Query.extractTerms with Weight.extractTerms.

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/lucene/   (props changed)
    lucene/dev/branches/branch_5x/lucene/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_5x/lucene/core/   (props changed)
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/CachingWrapperQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreWeight.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Filter.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiTermQueryConstantScoreWrapper.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Query.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Weight.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadSpanUtil.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanMultiTermQueryWrapper.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanWeight.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestNeedsScores.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/MultiSpansWrapper.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestFieldMaskingSpanQuery.java
    lucene/dev/branches/branch_5x/lucene/facet/   (props changed)
    lucene/dev/branches/branch_5x/lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java
    lucene/dev/branches/branch_5x/lucene/highlighter/   (props changed)
    lucene/dev/branches/branch_5x/lucene/highlighter/src/java/org/apache/lucene/search/highlight/QueryTermExtractor.java
    lucene/dev/branches/branch_5x/lucene/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java
    lucene/dev/branches/branch_5x/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/PostingsHighlighter.java
    lucene/dev/branches/branch_5x/lucene/join/   (props changed)
    lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsQuery.java
    lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java
    lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java
    lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
    lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
    lucene/dev/branches/branch_5x/lucene/queries/   (props changed)
    lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/CommonTermsQuery.java
    lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java
    lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/TermsQuery.java
    lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java
    lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java
    lucene/dev/branches/branch_5x/lucene/sandbox/   (props changed)
    lucene/dev/branches/branch_5x/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonQuery.java
    lucene/dev/branches/branch_5x/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/FuzzyLikeThisQueryTest.java
    lucene/dev/branches/branch_5x/lucene/spatial/   (props changed)
    lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/composite/CompositeVerifyQuery.java
    lucene/dev/branches/branch_5x/lucene/test-framework/   (props changed)
    lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/AssertingQuery.java
    lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/AssertingWeight.java
    lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/RandomApproximationQuery.java
    lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/ShardSearchingTestBase.java
    lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/spans/AssertingSpanQuery.java
    lucene/dev/branches/branch_5x/solr/   (props changed)
    lucene/dev/branches/branch_5x/solr/core/   (props changed)
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/schema/LatLonType.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/ExportQParserPlugin.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/SolrConstantScoreQuery.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/WrappedQuery.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/join/IgnoreAcceptDocsQuery.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/stats/ExactStatsCache.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/update/DeleteByQueryWrapper.java

Modified: lucene/dev/branches/branch_5x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/CHANGES.txt?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/lucene/CHANGES.txt Thu Apr 16 15:56:13 2015
@@ -80,6 +80,9 @@ API Changes
 * LUCENE-6410: Removed unused "reuse" parameter to
   Terms.iterator. (Robert Muir, Mike McCandless)
 
+* LUCENE-6425: Replaced Query.extractTerms with Weight.extractTerms.
+  (Adrien Grand)
+
 Other
 
 * LUCENE-6413: Test runner should report the number of suites completed/ 

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java Thu Apr 16 15:56:13 2015
@@ -233,16 +233,6 @@ public class BooleanQuery extends Query
     }
   }
 
-  // inherit javadoc
-  @Override
-  public void extractTerms(Set<Term> terms) {
-    for (BooleanClause clause : clauses) {
-      if (clause.isScoring()) {
-        clause.getQuery().extractTerms(terms);
-      }
-    }
-  }
-
   @Override @SuppressWarnings("unchecked")
   public BooleanQuery clone() {
     BooleanQuery clone = (BooleanQuery)super.clone();

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java Thu Apr 16 15:56:13 2015
@@ -22,8 +22,10 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.Term;
 import org.apache.lucene.search.BooleanClause.Occur;
 import org.apache.lucene.search.similarities.Similarity;
 import org.apache.lucene.util.Bits;
@@ -77,6 +79,17 @@ public class BooleanWeight extends Weigh
     }
   }
 
+  @Override
+  public void extractTerms(Set<Term> terms) {
+    int i = 0;
+    for (BooleanClause clause : query.clauses()) {
+      if (clause.isScoring() || (needsScores == false && clause.isProhibited() == false)) {
+        weights.get(i).extractTerms(terms);
+      }
+      i++;
+    }
+  }
+
   @Override
   public float getValueForNormalization() throws IOException {
     float sum = 0.0f;

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/CachingWrapperQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/CachingWrapperQuery.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/CachingWrapperQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/CachingWrapperQuery.java Thu Apr 16 15:56:13 2015
@@ -23,11 +23,13 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.WeakHashMap;
 
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.LeafReader;
 import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.Term;
 import org.apache.lucene.util.Accountable;
 import org.apache.lucene.util.Accountables;
 import org.apache.lucene.util.Bits;
@@ -116,7 +118,12 @@ public class CachingWrapperQuery extends
     policy.onUse(weight.getQuery());
     return new ConstantScoreWeight(weight.getQuery()) {
       @Override
-      protected Scorer scorer(LeafReaderContext context, final Bits acceptDocs, float score) throws IOException {
+      public void extractTerms(Set<Term> terms) {
+        weight.extractTerms(terms);
+      }
+
+      @Override
+      protected Scorer scorer(LeafReaderContext context, final Bits acceptDocs, final float score) throws IOException {
         final LeafReader reader = context.reader();
         final Object key = reader.getCoreCacheKey();
 

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java Thu Apr 16 15:56:13 2015
@@ -62,16 +62,6 @@ public class ConstantScoreQuery extends
     return this;
   }
 
-  @Override
-  public void extractTerms(Set<Term> terms) {
-    // NOTE: ConstantScoreQuery used to wrap either a query or a filter. Now
-    // that filter extends Query, we need to only extract terms when the query
-    // is not a filter if we do not want to hit an UnsupportedOperationException
-    if (query instanceof Filter == false) {
-      query.extractTerms(terms);
-    }
-  }
-
   protected class ConstantWeight extends Weight {
     private final Weight innerWeight;
     private float queryNorm;
@@ -83,6 +73,11 @@ public class ConstantScoreQuery extends
     }
 
     @Override
+    public void extractTerms(Set<Term> terms) {
+      // no-op
+    }
+
+    @Override
     public float getValueForNormalization() throws IOException {
       // we calculate sumOfSquaredWeights of the inner weight, but ignore it (just to initialize everything)
       innerWeight.getValueForNormalization();

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreWeight.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreWeight.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreWeight.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreWeight.java Thu Apr 16 15:56:13 2015
@@ -18,8 +18,10 @@ package org.apache.lucene.search;
  */
 
 import java.io.IOException;
+import java.util.Set;
 
 import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.Term;
 import org.apache.lucene.util.Bits;
 
 /**
@@ -37,6 +39,13 @@ public abstract class ConstantScoreWeigh
   }
 
   @Override
+  public void extractTerms(Set<Term> terms) {
+    // most constant-score queries don't wrap index terms
+    // eg. geo filters, doc values queries, ...
+    // override if your constant-score query does wrap terms
+  }
+
+  @Override
   public final float getValueForNormalization() throws IOException {
     queryWeight = getQuery().getBoost();
     return queryWeight * queryWeight;

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java Thu Apr 16 15:56:13 2015
@@ -127,6 +127,13 @@ public class DisjunctionMaxQuery extends
       this.needsScores = needsScores;
     }
 
+    @Override
+    public void extractTerms(Set<Term> terms) {
+      for (Weight weight : weights) {
+        weight.extractTerms(terms);
+      }
+    }
+
     /** Compute the sub of squared weights of us applied to our subqueries.  Used for normalization. */
     @Override
     public float getValueForNormalization() throws IOException {
@@ -237,14 +244,6 @@ public class DisjunctionMaxQuery extends
     return clone;
   }
 
-  // inherit javadoc
-  @Override
-  public void extractTerms(Set<Term> terms) {
-    for (Query query : disjuncts) {
-      query.extractTerms(terms);
-    }
-  }
-
   /** Prettyprint us.
    * @param field the field to which we are applied
    * @return a string that shows what we do, of the form "(disjunct1 | disjunct2 | ... | disjunctn)^boost"

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Filter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Filter.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Filter.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Filter.java Thu Apr 16 15:56:13 2015
@@ -18,8 +18,10 @@ package org.apache.lucene.search;
  */
 
 import java.io.IOException;
+import java.util.Set;
 
 import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.Term;
 import org.apache.lucene.util.Bits;
 
 /**
@@ -79,6 +81,9 @@ public abstract class Filter extends Que
     return new Weight(this) {
 
       @Override
+      public void extractTerms(Set<Term> terms) {}
+
+      @Override
       public float getValueForNormalization() throws IOException {
         return 0f;
       }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java Thu Apr 16 15:56:13 2015
@@ -90,6 +90,11 @@ public class FilteredQuery extends Query
     return new Weight(FilteredQuery.this) {
 
       @Override
+      public void extractTerms(Set<Term> terms) {
+        weight.extractTerms(terms);
+      }
+
+      @Override
       public float getValueForNormalization() throws IOException { 
         return weight.getValueForNormalization() * getBoost() * getBoost(); // boost sub-weight
       }
@@ -371,12 +376,6 @@ public class FilteredQuery extends Query
     return this.strategy;
   }
 
-  // inherit javadoc
-  @Override
-  public void extractTerms(Set<Term> terms) {
-    getQuery().extractTerms(terms);
-  }
-
   /** Prints a user-readable version of this query. */
   @Override
   public String toString (String s) {

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java Thu Apr 16 15:56:13 2015
@@ -30,6 +30,7 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.lucene.index.LeafReader;
+import org.apache.lucene.index.Term;
 import org.apache.lucene.index.LeafReader.CoreClosedListener;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.util.Accountable;
@@ -563,7 +564,12 @@ public class LRUQueryCache implements Qu
     }
 
     @Override
-    protected Scorer scorer(LeafReaderContext context, final Bits acceptDocs, float score) throws IOException {
+    public void extractTerms(Set<Term> terms) {
+      in.extractTerms(terms);
+    }
+
+    @Override
+    protected Scorer scorer(LeafReaderContext context, final Bits acceptDocs, final float score) throws IOException {
       if (context.ord == 0) {
         policy.onUse(getQuery());
       }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java Thu Apr 16 15:56:13 2015
@@ -93,6 +93,9 @@ public final class MatchAllDocsQuery ext
     }
 
     @Override
+    public void extractTerms(Set<Term> terms) {}
+
+    @Override
     public String toString() {
       return "weight(" + MatchAllDocsQuery.this + ")";
     }
@@ -134,10 +137,6 @@ public final class MatchAllDocsQuery ext
   }
 
   @Override
-  public void extractTerms(Set<Term> terms) {
-  }
-
-  @Override
   public String toString(String field) {
     StringBuilder buffer = new StringBuilder();
     buffer.append("*:*");

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java Thu Apr 16 15:56:13 2015
@@ -126,16 +126,6 @@ public class MultiPhraseQuery extends Qu
     return result;
   }
 
-  // inherit javadoc
-  @Override
-  public void extractTerms(Set<Term> terms) {
-    for (final Term[] arr : termArrays) {
-      for (final Term term: arr) {
-        terms.add(term);
-      }
-    }
-  }
-
 
   private class MultiPhraseWeight extends Weight {
     private final Similarity similarity;
@@ -168,6 +158,15 @@ public class MultiPhraseQuery extends Qu
     }
 
     @Override
+    public void extractTerms(Set<Term> terms) {
+      for (final Term[] arr : termArrays) {
+        for (final Term term: arr) {
+          terms.add(term);
+        }
+      }
+    }
+
+    @Override
     public float getValueForNormalization() {
       return stats.getValueForNormalization();
     }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiTermQueryConstantScoreWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiTermQueryConstantScoreWrapper.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiTermQueryConstantScoreWrapper.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiTermQueryConstantScoreWrapper.java Thu Apr 16 15:56:13 2015
@@ -75,11 +75,6 @@ final class MultiTermQueryConstantScoreW
     return Objects.hash(getClass(), query, getBoost());
   }
 
-  @Override
-  public void extractTerms(Set<Term> terms) {
-    // no-op
-  }
-
   /** Returns the field name for this query */
   public final String getField() { return query.getField(); }
 

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java Thu Apr 16 15:56:13 2015
@@ -266,6 +266,11 @@ public class PhraseQuery extends Query {
     }
 
     @Override
+    public void extractTerms(Set<Term> queryTerms) {
+      queryTerms.addAll(terms);
+    }
+
+    @Override
     public String toString() { return "weight(" + PhraseQuery.this + ")"; }
 
     @Override
@@ -353,14 +358,6 @@ public class PhraseQuery extends Query {
     return new PhraseWeight(searcher, needsScores);
   }
 
-  /**
-   * @see org.apache.lucene.search.Query#extractTerms(Set)
-   */
-  @Override
-  public void extractTerms(Set<Term> queryTerms) {
-    queryTerms.addAll(terms);
-  }
-
   /** Prints a user-readable version of this query. */
   @Override
   public String toString(String f) {

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Query.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Query.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Query.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Query.java Thu Apr 16 15:56:13 2015
@@ -18,10 +18,8 @@ package org.apache.lucene.search;
  */
 
 import java.io.IOException;
-import java.util.Set;
 
 import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.Term;
 
 /** The abstract base class for queries.
     <p>Instantiable subclasses are:
@@ -88,17 +86,6 @@ public abstract class Query implements C
   public Query rewrite(IndexReader reader) throws IOException {
     return this;
   }
-  
-  /**
-   * Expert: adds all terms occurring in this query to the terms set. Only
-   * works if this query is in its {@link #rewrite rewritten} form.
-   * 
-   * @throws UnsupportedOperationException if this query is not yet rewritten
-   */
-  public void extractTerms(Set<Term> terms) {
-    // needs to be implemented by query subclasses
-    throw new UnsupportedOperationException(getClass().getName());
-  }
 
   /** Returns a clone of this query. */
   @Override

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermQuery.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermQuery.java Thu Apr 16 15:56:13 2015
@@ -60,7 +60,12 @@ public class TermQuery extends Query {
           searcher.collectionStatistics(term.field()),
           searcher.termStatistics(term, termStates));
     }
-    
+
+    @Override
+    public void extractTerms(Set<Term> terms) {
+      terms.add(getTerm());
+    }
+
     @Override
     public String toString() {
       return "weight(" + TermQuery.this + ")";
@@ -174,11 +179,6 @@ public class TermQuery extends Query {
     return new TermWeight(searcher, needsScores, termState);
   }
   
-  @Override
-  public void extractTerms(Set<Term> terms) {
-    terms.add(getTerm());
-  }
-  
   /** Prints a user-readable version of this query. */
   @Override
   public String toString(String field) {

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Weight.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Weight.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Weight.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Weight.java Thu Apr 16 15:56:13 2015
@@ -18,9 +18,11 @@ package org.apache.lucene.search;
  */
 
 import java.io.IOException;
+import java.util.Set;
 
 import org.apache.lucene.index.IndexReaderContext;
 import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.Term;
 import org.apache.lucene.search.similarities.Similarity;
 import org.apache.lucene.util.Bits;
 
@@ -66,6 +68,14 @@ public abstract class Weight {
   }
 
   /**
+   * Expert: adds all terms occurring in this query to the terms set. If the
+   * {@link Weight} was created with {@code needsScores == true} then this
+   * method will only extract terms which are used for scoring, otherwise it
+   * will extract all terms which are used for matching.
+   */
+  public abstract void extractTerms(Set<Term> terms);
+
+  /**
    * An explanation of the score computation for the named document.
    * 
    * @param context the readers context to create the {@link Explanation} for.

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadSpanUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadSpanUtil.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadSpanUtil.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadSpanUtil.java Thu Apr 16 15:56:13 2015
@@ -26,15 +26,16 @@ import java.util.List;
 import java.util.Map;
 import java.util.TreeSet;
 
-import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.BooleanClause;
 import org.apache.lucene.search.BooleanQuery;
 import org.apache.lucene.search.DisjunctionMaxQuery;
 import org.apache.lucene.search.FilteredQuery;
+import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.MultiPhraseQuery;
 import org.apache.lucene.search.PhraseQuery;
 import org.apache.lucene.search.Query;
@@ -180,7 +181,9 @@ public class PayloadSpanUtil {
       throws IOException {
     Map<Term,TermContext> termContexts = new HashMap<>();
     TreeSet<Term> terms = new TreeSet<>();
-    query.extractTerms(terms);
+    final IndexSearcher searcher = new IndexSearcher(context);
+    searcher.setQueryCache(null);
+    searcher.createNormalizedWeight(query, false).extractTerms(terms);
     for (Term term : terms) {
       termContexts.put(term, TermContext.build(context, term));
     }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanMultiTermQueryWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanMultiTermQueryWrapper.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanMultiTermQueryWrapper.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanMultiTermQueryWrapper.java Thu Apr 16 15:56:13 2015
@@ -19,6 +19,7 @@ package org.apache.lucene.search.spans;
 
 import java.io.IOException;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.IndexReader;
@@ -72,7 +73,12 @@ public class SpanMultiTermQueryWrapper<Q
       setRewriteMethod(SCORING_SPAN_QUERY_REWRITE); 
     }
   }
-  
+
+  @Override
+  protected void extractTerms(Set<Term> terms) {
+    throw new IllegalStateException("Rewrite first");
+  }
+
   /**
    * Expert: returns the rewriteMethod
    */

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanQuery.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanQuery.java Thu Apr 16 15:56:13 2015
@@ -19,12 +19,14 @@ package org.apache.lucene.search.spans;
 
 import java.io.IOException;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
-import org.apache.lucene.search.Query;
 import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.Weight;
 import org.apache.lucene.util.Bits;
 
 /** Base class for span-based queries. */
@@ -36,6 +38,13 @@ public abstract class SpanQuery extends
   public abstract Spans getSpans(LeafReaderContext context, Bits acceptDocs, Map<Term,TermContext> termContexts) throws IOException;
 
   /**
+   * Extract terms from these spans.
+   * @lucene.internal
+   * @see Weight#extractTerms
+   */
+  protected abstract void extractTerms(Set<Term> terms);
+
+  /**
    * Returns the name of the field matched by this query.
    * <p>
    * Note that this may return null if the query matches no terms.

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanWeight.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanWeight.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanWeight.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanWeight.java Thu Apr 16 15:56:13 2015
@@ -20,6 +20,7 @@ package org.apache.lucene.search.spans;
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Set;
 import java.util.TreeSet;
 
 import org.apache.lucene.index.IndexReaderContext;
@@ -72,6 +73,11 @@ public class SpanWeight extends Weight {
   }
 
   @Override
+  public void extractTerms(Set<Term> terms) {
+    query.extractTerms(terms);
+  }
+
+  @Override
   public float getValueForNormalization() throws IOException {
     return stats == null ? 1.0f : stats.getValueForNormalization();
   }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java Thu Apr 16 15:56:13 2015
@@ -18,9 +18,11 @@ package org.apache.lucene.search;
  */
 
 import java.io.IOException;
+import java.util.Set;
 
 import org.apache.lucene.index.FieldInvertState;
 import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.Term;
 import org.apache.lucene.search.similarities.Similarity;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.PriorityQueue;
@@ -276,6 +278,11 @@ final class JustCompileSearch {
     }
 
     @Override
+    public void extractTerms(Set<Term> terms) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    @Override
     public Explanation explain(LeafReaderContext context, int doc) {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);
     }
@@ -294,7 +301,7 @@ final class JustCompileSearch {
     public Scorer scorer(LeafReaderContext context, Bits acceptDocs) {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);
     }
-    
+
   }
   
 }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java Thu Apr 16 15:56:13 2015
@@ -762,7 +762,7 @@ public class TestBooleanQuery extends Lu
     assertEquals("a +b -c #d", bq.toString("field"));
   }
 
-  public void testExtractTerms() {
+  public void testExtractTerms() throws IOException {
     Term a = new Term("f", "a");
     Term b = new Term("f", "b");
     Term c = new Term("f", "c");
@@ -772,8 +772,14 @@ public class TestBooleanQuery extends Lu
     bq.add(new TermQuery(b), Occur.MUST);
     bq.add(new TermQuery(c), Occur.FILTER);
     bq.add(new TermQuery(d), Occur.MUST_NOT);
-    Set<Term> terms = new HashSet<>();
-    bq.extractTerms(terms);
-    assertEquals(new HashSet<>(Arrays.asList(a, b)), terms);
+    IndexSearcher searcher = new IndexSearcher(new MultiReader());
+
+    Set<Term> scoringTerms = new HashSet<>();
+    searcher.createNormalizedWeight(bq, true).extractTerms(scoringTerms);
+    assertEquals(new HashSet<>(Arrays.asList(a, b)), scoringTerms);
+
+    Set<Term> matchingTerms = new HashSet<>();
+    searcher.createNormalizedWeight(bq, false).extractTerms(matchingTerms);
+    assertEquals(new HashSet<>(Arrays.asList(a, b, c)), matchingTerms);
   }
 }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java Thu Apr 16 15:56:13 2015
@@ -18,6 +18,7 @@ package org.apache.lucene.search;
  */
 
 import java.io.IOException;
+import java.util.Set;
 
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
@@ -73,6 +74,11 @@ public class TestBooleanScorer extends L
     public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
       return new Weight(CrazyMustUseBulkScorerQuery.this) {
         @Override
+        public void extractTerms(Set<Term> terms) {
+          throw new UnsupportedOperationException();
+        }
+
+        @Override
         public Explanation explain(LeafReaderContext context, int doc) {
           throw new UnsupportedOperationException();
         }

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=1674100&r1=1674099&r2=1674100&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 Thu Apr 16 15:56:13 2015
@@ -18,12 +18,16 @@ package org.apache.lucene.search;
  */
 
 import java.io.IOException;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
 
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.MultiReader;
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.similarities.DefaultSimilarity;
@@ -231,4 +235,18 @@ public class TestConstantScoreQuery exte
     w.close();
     dir.close();
   }
+
+  public void testExtractTerms() throws Exception {
+    final IndexSearcher searcher = newSearcher(new MultiReader());
+    final TermQuery termQuery = new TermQuery(new Term("foo", "bar"));
+    final ConstantScoreQuery csq = new ConstantScoreQuery(termQuery);
+
+    final Set<Term> scoringTerms = new HashSet<>();
+    searcher.createNormalizedWeight(csq, true).extractTerms(scoringTerms);
+    assertEquals(Collections.emptySet(), scoringTerms);
+
+    final Set<Term> matchingTerms = new HashSet<>();
+    searcher.createNormalizedWeight(csq, false).extractTerms(matchingTerms);
+    assertEquals(Collections.singleton(new Term("foo", "bar")), matchingTerms);
+  }
 }

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=1674100&r1=1674099&r2=1674100&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 Thu Apr 16 15:56:13 2015
@@ -113,6 +113,11 @@ public class TestNeedsScores extends Luc
       final Weight w = in.createWeight(searcher, needsScores);
       return new Weight(AssertNeedsScores.this) {
         @Override
+        public void extractTerms(Set<Term> terms) {
+          w.extractTerms(terms);
+        }
+
+        @Override
         public Explanation explain(LeafReaderContext context, int doc) throws IOException {
           return w.explain(context, doc);
         }
@@ -146,11 +151,6 @@ public class TestNeedsScores extends Luc
     }
 
     @Override
-    public void extractTerms(Set<Term> terms) {
-      in.extractTerms(terms);
-    }
-
-    @Override
     public int hashCode() {
       final int prime = 31;
       int result = super.hashCode();

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=1674100&r1=1674099&r2=1674100&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 Thu Apr 16 15:56:13 2015
@@ -429,6 +429,10 @@ public class TestQueryRescorer extends L
       return new Weight(FixedScoreQuery.this) {
 
         @Override
+        public void extractTerms(Set<Term> terms) {
+        }
+
+        @Override
         public float getValueForNormalization() {
           return 1.0f;
         }
@@ -495,10 +499,6 @@ public class TestQueryRescorer extends L
     }
 
     @Override
-    public void extractTerms(Set<Term> terms) {
-    }
-
-    @Override
     public String toString(String field) {
       return "FixedScoreQuery " + idToNum.length + " ids; reverse=" + reverse;
     }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java Thu Apr 16 15:56:13 2015
@@ -20,6 +20,7 @@ package org.apache.lucene.search.spans;
 import java.io.IOException;
 import java.util.Collection;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
@@ -89,6 +90,11 @@ final class JustCompileSearchSpans {
   static final class JustCompileSpanQuery extends SpanQuery {
 
     @Override
+    protected void extractTerms(Set<Term> terms) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    @Override
     public String getField() {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);
     }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/MultiSpansWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/MultiSpansWrapper.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/MultiSpansWrapper.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/MultiSpansWrapper.java Thu Apr 16 15:56:13 2015
@@ -28,7 +28,6 @@ import org.apache.lucene.index.LeafReade
 import org.apache.lucene.index.SlowCompositeReaderWrapper;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
-import org.apache.lucene.search.Query;
 import org.apache.lucene.util.Bits;
 
 /**
@@ -43,7 +42,7 @@ public class MultiSpansWrapper {
   public static Spans wrap(IndexReader reader, SpanQuery spanQuery) throws IOException {
     LeafReader lr = SlowCompositeReaderWrapper.wrap(reader); // slow, but ok for testing
     LeafReaderContext lrContext = lr.getContext();
-    Query rewrittenQuery = spanQuery.rewrite(lr); // get the term contexts so getSpans can be called directly
+    SpanQuery rewrittenQuery = (SpanQuery) spanQuery.rewrite(lr); // get the term contexts so getSpans can be called directly
     HashSet<Term> termSet = new HashSet<>();
     rewrittenQuery.extractTerms(termSet);
     Map<Term,TermContext> termContexts = new HashMap<>();

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=1674100&r1=1674099&r2=1674100&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 Thu Apr 16 15:56:13 2015
@@ -175,7 +175,7 @@ public class TestFieldMaskingSpanQuery e
     QueryUtils.checkEqual(q, qr);
 
     HashSet<Term> set = new HashSet<>();
-    qr.extractTerms(set);
+    qr.createWeight(searcher, true).extractTerms(set);
     assertEquals(2, set.size());
   }
   

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=1674100&r1=1674099&r2=1674100&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 Thu Apr 16 15:56:13 2015
@@ -18,9 +18,11 @@ package org.apache.lucene.facet;
  */
 import java.io.IOException;
 import java.util.Arrays;
+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.BulkScorer;
 import org.apache.lucene.search.Collector;
 import org.apache.lucene.search.DocIdSet;
@@ -92,6 +94,9 @@ class DrillSidewaysQuery extends Query {
 
     return new Weight(DrillSidewaysQuery.this) {
       @Override
+      public void extractTerms(Set<Term> terms) {}
+
+      @Override
       public Explanation explain(LeafReaderContext context, int doc) throws IOException {
         return baseWeight.explain(context, doc);
       }

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=1674100&r1=1674099&r2=1674100&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 Thu Apr 16 15:56:13 2015
@@ -21,10 +21,12 @@ import java.util.HashSet;
 import java.util.Iterator;
 
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.MultiReader;
 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.IndexSearcher;
 import org.apache.lucene.search.Query;
 
 /**
@@ -37,6 +39,18 @@ import org.apache.lucene.search.Query;
 public final class QueryTermExtractor
 {
 
+  /** for term extraction */
+  private static final IndexSearcher EMPTY_INDEXSEARCHER;
+  static {
+    try {
+      IndexReader emptyReader = new MultiReader();
+      EMPTY_INDEXSEARCHER = new IndexSearcher(emptyReader);
+      EMPTY_INDEXSEARCHER.setQueryCache(null);
+    } catch (IOException bogus) {
+      throw new RuntimeException(bogus);
+    }
+  }
+
   /**
    * Extracts all terms texts of a given Query into an array of WeightedTerms
    *
@@ -113,7 +127,11 @@ public final class QueryTermExtractor
         getTermsFromFilteredQuery((FilteredQuery) query, terms, prohibited, fieldName);
       else {
         HashSet<Term> nonWeightedTerms = new HashSet<>();
-        query.extractTerms(nonWeightedTerms);
+        try {
+          EMPTY_INDEXSEARCHER.createNormalizedWeight(query, false).extractTerms(nonWeightedTerms);
+        } catch (IOException bogus) {
+          throw new RuntimeException("Should not happen on an empty index", bogus);
+        }
         for (Iterator<Term> iter = nonWeightedTerms.iterator(); iter.hasNext(); ) {
           Term term = iter.next();
           if ((fieldName == null) || (term.field().equals(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=1674100&r1=1674099&r2=1674100&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 Thu Apr 16 15:56:13 2015
@@ -278,14 +278,16 @@ public class WeightedSpanTermExtractor {
  
     Set<Term> nonWeightedTerms = new HashSet<>();
     final boolean mustRewriteQuery = mustRewriteQuery(spanQuery);
+    final IndexSearcher searcher = new IndexSearcher(getLeafContext());
+    searcher.setQueryCache(null);
     if (mustRewriteQuery) {
       for (final String field : fieldNames) {
         final SpanQuery rewrittenQuery = (SpanQuery) spanQuery.rewrite(getLeafContext().reader());
         queries.put(field, rewrittenQuery);
-        rewrittenQuery.extractTerms(nonWeightedTerms);
+        rewrittenQuery.createWeight(searcher, false).extractTerms(nonWeightedTerms);
       }
     } else {
-      spanQuery.extractTerms(nonWeightedTerms);
+      spanQuery.createWeight(searcher, false).extractTerms(nonWeightedTerms);
     }
 
     List<PositionSpan> spanPositions = new ArrayList<>();
@@ -300,7 +302,7 @@ public class WeightedSpanTermExtractor {
       LeafReaderContext context = getLeafContext();
       Map<Term,TermContext> termContexts = new HashMap<>();
       TreeSet<Term> extractedTerms = new TreeSet<>();
-      q.extractTerms(extractedTerms);
+      searcher.createNormalizedWeight(q, false).extractTerms(extractedTerms);
       for (Term term : extractedTerms) {
         termContexts.put(term, TermContext.build(context, term));
       }
@@ -353,7 +355,8 @@ public class WeightedSpanTermExtractor {
    */
   protected void extractWeightedTerms(Map<String,WeightedSpanTerm> terms, Query query) throws IOException {
     Set<Term> nonWeightedTerms = new HashSet<>();
-    query.extractTerms(nonWeightedTerms);
+    final IndexSearcher searcher = new IndexSearcher(getLeafContext());
+    searcher.createNormalizedWeight(query, false).extractTerms(nonWeightedTerms);
 
     for (final Term queryTerm : nonWeightedTerms) {
 

Modified: lucene/dev/branches/branch_5x/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/PostingsHighlighter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/PostingsHighlighter.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/PostingsHighlighter.java (original)
+++ lucene/dev/branches/branch_5x/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/PostingsHighlighter.java Thu Apr 16 15:56:13 2015
@@ -101,10 +101,12 @@ public class PostingsHighlighter {
   // unnecessary.
   
   /** for rewriting: we don't want slow processing from MTQs */
-  private static final IndexReader EMPTY_INDEXREADER;
+  private static final IndexSearcher EMPTY_INDEXSEARCHER;
   static {
     try {
-      EMPTY_INDEXREADER = new MultiReader();
+      IndexReader emptyReader = new MultiReader();
+      EMPTY_INDEXSEARCHER = new IndexSearcher(emptyReader);
+      EMPTY_INDEXSEARCHER.setQueryCache(null);
     } catch (IOException bogus) {
       throw new RuntimeException(bogus);
     }
@@ -352,12 +354,10 @@ public class PostingsHighlighter {
     if (fieldsIn.length != maxPassagesIn.length) {
       throw new IllegalArgumentException("invalid number of maxPassagesIn");
     }
-    final IndexReader reader = searcher.getIndexReader();
-    Query rewritten = rewrite(query);
     SortedSet<Term> queryTerms = new TreeSet<>();
-    rewritten.extractTerms(queryTerms);
+    EMPTY_INDEXSEARCHER.createNormalizedWeight(query, false).extractTerms(queryTerms);
 
-    IndexReaderContext readerContext = reader.getContext();
+    IndexReaderContext readerContext = searcher.getIndexReader().getContext();
     List<LeafReaderContext> leaves = readerContext.leaves();
 
     // Make our own copies because we sort in-place:
@@ -509,10 +509,8 @@ public class PostingsHighlighter {
           // no offsets available
           throw new IllegalArgumentException("field '" + field + "' was indexed without offsets, cannot highlight");
         }
-        if (t != null) {
-          termsEnum = t.iterator();
-          postings = new PostingsEnum[terms.length];
-        }
+        termsEnum = t.iterator();
+        postings = new PostingsEnum[terms.length];
       }
       if (termsEnum == null) {
         continue; // no terms for this field, nothing to do
@@ -761,19 +759,6 @@ public class PostingsHighlighter {
     public long cost() { return 0; }
   };
   
-  /** 
-   * we rewrite against an empty indexreader: as we don't want things like
-   * rangeQueries that don't summarize the document
-   */
-  private static Query rewrite(Query original) throws IOException {
-    Query query = original;
-    for (Query rewrittenQuery = query.rewrite(EMPTY_INDEXREADER); rewrittenQuery != query;
-         rewrittenQuery = query.rewrite(EMPTY_INDEXREADER)) {
-      query = rewrittenQuery;
-    }
-    return query;
-  }
-  
   private static class LimitedStoredFieldVisitor extends StoredFieldVisitor {
     private final String fields[];
     private final char valueSeparators[];

Modified: lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsQuery.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsQuery.java Thu Apr 16 15:56:13 2015
@@ -67,11 +67,6 @@ final class GlobalOrdinalsQuery extends
   }
 
   @Override
-  public void extractTerms(Set<Term> terms) {
-    fromQuery.extractTerms(terms);
-  }
-
-  @Override
   public boolean equals(Object o) {
     if (this == o) return true;
     if (o == null || getClass() != o.getClass()) return false;
@@ -117,6 +112,9 @@ final class GlobalOrdinalsQuery extends
     }
 
     @Override
+    public void extractTerms(Set<Term> terms) {}
+
+    @Override
     public Explanation explain(LeafReaderContext context, int doc) throws IOException {
       SortedDocValues values = DocValues.getSorted(context.reader(), joinField);
       if (values != null) {

Modified: lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java Thu Apr 16 15:56:13 2015
@@ -65,11 +65,6 @@ final class GlobalOrdinalsWithScoreQuery
   }
 
   @Override
-  public void extractTerms(Set<Term> terms) {
-    fromQuery.extractTerms(terms);
-  }
-
-  @Override
   public boolean equals(Object o) {
     if (this == o) return true;
     if (o == null || getClass() != o.getClass()) return false;
@@ -115,6 +110,9 @@ final class GlobalOrdinalsWithScoreQuery
     }
 
     @Override
+    public void extractTerms(Set<Term> terms) {}
+
+    @Override
     public Explanation explain(LeafReaderContext context, int doc) throws IOException {
       SortedDocValues values = DocValues.getSorted(context.reader(), joinField);
       if (values != null) {

Modified: lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java Thu Apr 16 15:56:13 2015
@@ -76,11 +76,6 @@ class TermsIncludingScoreQuery extends Q
   }
 
   @Override
-  public void extractTerms(Set<Term> terms) {
-    originalQuery.extractTerms(terms);
-  }
-
-  @Override
   public Query rewrite(IndexReader reader) throws IOException {
     final Query originalQueryRewrite = originalQuery.rewrite(reader);
     if (originalQueryRewrite != originalQuery) {
@@ -128,6 +123,9 @@ class TermsIncludingScoreQuery extends Q
     return new Weight(TermsIncludingScoreQuery.this) {
 
       @Override
+      public void extractTerms(Set<Term> terms) {}
+
+      @Override
       public Explanation explain(LeafReaderContext context, int doc) throws IOException {
         Terms terms = context.reader().terms(field);
         if (terms != null) {

Modified: lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java Thu Apr 16 15:56:13 2015
@@ -106,6 +106,9 @@ public class ToChildBlockJoinQuery exten
     }
 
     @Override
+    public void extractTerms(Set<Term> terms) {}
+
+    @Override
     public float getValueForNormalization() throws IOException {
       return parentWeight.getValueForNormalization() * joinQuery.getBoost() * joinQuery.getBoost();
     }
@@ -314,11 +317,6 @@ public class ToChildBlockJoinQuery exten
   }
 
   @Override
-  public void extractTerms(Set<Term> terms) {
-    parentQuery.extractTerms(terms);
-  }
-
-  @Override
   public Query rewrite(IndexReader reader) throws IOException {
     final Query parentRewrite = parentQuery.rewrite(reader);
     if (parentRewrite != parentQuery) {

Modified: lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java Thu Apr 16 15:56:13 2015
@@ -143,6 +143,9 @@ public class ToParentBlockJoinQuery exte
     }
 
     @Override
+    public void extractTerms(Set<Term> terms) {}
+
+    @Override
     public float getValueForNormalization() throws IOException {
       return childWeight.getValueForNormalization() * joinQuery.getBoost() * joinQuery.getBoost();
     }
@@ -428,11 +431,6 @@ public class ToParentBlockJoinQuery exte
   }
 
   @Override
-  public void extractTerms(Set<Term> terms) {
-    childQuery.extractTerms(terms);
-  }
-
-  @Override
   public Query rewrite(IndexReader reader) throws IOException {
     final Query childRewrite = childQuery.rewrite(reader);
     if (childRewrite != childQuery) {

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=1674100&r1=1674099&r2=1674100&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 Thu Apr 16 15:56:13 2015
@@ -34,7 +34,6 @@ import org.apache.lucene.util.ToStringUt
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Set;
 
 /**
  * A query that executes high-frequency terms in a optional sub-query to prevent
@@ -333,11 +332,6 @@ public class CommonTermsQuery extends Qu
   }
   
   @Override
-  public void extractTerms(Set<Term> terms) {
-    terms.addAll(this.terms);
-  }
-  
-  @Override
   public String toString(String field) {
     StringBuilder buffer = new StringBuilder();
     boolean needParens = (getBoost() != 1.0)

Modified: lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java Thu Apr 16 15:56:13 2015
@@ -34,7 +34,6 @@ import org.apache.lucene.search.FilterSc
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.Scorer;
-import org.apache.lucene.search.TwoPhaseIterator;
 import org.apache.lucene.search.Weight;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.ToStringUtils;
@@ -109,15 +108,6 @@ public class CustomScoreQuery extends Qu
     return (clone == null) ? this : clone;
   }
 
-  /*(non-Javadoc) @see org.apache.lucene.search.Query#extractTerms(java.util.Set) */
-  @Override
-  public void extractTerms(Set<Term> terms) {
-    subQuery.extractTerms(terms);
-    for (Query scoringQuery : scoringQueries) {
-      scoringQuery.extractTerms(terms);
-    }
-  }
-
   /*(non-Javadoc) @see org.apache.lucene.search.Query#clone() */
   @Override
   public CustomScoreQuery clone() {
@@ -199,6 +189,14 @@ public class CustomScoreQuery extends Qu
     }
 
     @Override
+    public void extractTerms(Set<Term> terms) {
+      subQueryWeight.extractTerms(terms);
+      for (Weight scoringWeight : valSrcWeights) {
+        scoringWeight.extractTerms(terms);
+      }
+    }
+
+    @Override
     public float getValueForNormalization() throws IOException {
       float sum = subQueryWeight.getValueForNormalization();
       for (Weight valSrcWeight : valSrcWeights) {

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=1674100&r1=1674099&r2=1674100&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 Thu Apr 16 15:56:13 2015
@@ -262,14 +262,6 @@ public class TermsQuery extends Query im
     return Collections.emptyList();
   }
 
-  @Override
-  public void extractTerms(Set<Term> terms) {
-    // no-op
-    // This query is for abuse cases when the number of terms is too high to
-    // run efficiently as a BooleanQuery. So likewise we hide its terms in
-    // order to protect highlighters
-  }
-
   private static final class TermsAndField implements Accountable {
 
     private static final long BASE_RAM_BYTES_USED =
@@ -361,6 +353,14 @@ public class TermsQuery extends Query im
       private float queryWeight;
 
       @Override
+      public void extractTerms(Set<Term> terms) {
+        // no-op
+        // This query is for abuse cases when the number of terms is too high to
+        // run efficiently as a BooleanQuery. So likewise we hide its terms in
+        // order to protect highlighters
+      }
+
+      @Override
       public float getValueForNormalization() throws IOException {
         queryWeight = getBoost();
         return queryWeight * queryWeight;

Modified: lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java Thu Apr 16 15:56:13 2015
@@ -63,11 +63,6 @@ public class BoostedQuery extends Query
   }
 
   @Override
-  public void extractTerms(Set<Term> terms) {
-    q.extractTerms(terms);
-  }
-
-  @Override
   public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
     return new BoostedQuery.BoostedWeight(searcher, needsScores);
   }
@@ -86,6 +81,11 @@ public class BoostedQuery extends Query
     }
 
     @Override
+    public void extractTerms(Set<Term> terms) {
+      qWeight.extractTerms(terms);
+    }
+
+    @Override
     public float getValueForNormalization() throws IOException {
       float sum = qWeight.getValueForNormalization();
       sum *= getBoost() * getBoost();

Modified: lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java Thu Apr 16 15:56:13 2015
@@ -61,9 +61,6 @@ public class FunctionQuery extends Query
     return this;
   }
 
-  @Override
-  public void extractTerms(Set<Term> terms) {}
-
   protected class FunctionWeight extends Weight {
     protected final IndexSearcher searcher;
     protected float queryNorm;
@@ -78,6 +75,9 @@ public class FunctionQuery extends Query
     }
 
     @Override
+    public void extractTerms(Set<Term> terms) {}
+
+    @Override
     public float getValueForNormalization() throws IOException {
       queryWeight = getBoost();
       return queryWeight * queryWeight;

Modified: lucene/dev/branches/branch_5x/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonQuery.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonQuery.java Thu Apr 16 15:56:13 2015
@@ -202,15 +202,6 @@ public class TermAutomatonQuery extends
   }
 
   @Override
-  public void extractTerms(Set<Term> terms) {
-    for(BytesRef text : termToID.keySet()) {
-      if (text != null) {
-        terms.add(new Term(field, text));
-      }
-    }
-  }
-
-  @Override
   public String toString(String field) {
     // TODO: what really am I supposed to do with the incoming field...
     StringBuilder sb = new StringBuilder();
@@ -366,6 +357,15 @@ public class TermAutomatonQuery extends
     }
 
     @Override
+    public void extractTerms(Set<Term> terms) {
+      for(BytesRef text : termToID.keySet()) {
+        if (text != null) {
+          terms.add(new Term(field, text));
+        }
+      }
+    }
+
+    @Override
     public String toString() {
       return "weight(" + TermAutomatonQuery.this + ")";
     }

Modified: lucene/dev/branches/branch_5x/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/FuzzyLikeThisQueryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/FuzzyLikeThisQueryTest.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/FuzzyLikeThisQueryTest.java (original)
+++ lucene/dev/branches/branch_5x/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/FuzzyLikeThisQueryTest.java Thu Apr 16 15:56:13 2015
@@ -81,7 +81,7 @@ public class FuzzyLikeThisQueryTest exte
     flt.addTerms("smith", "name", 0.3f, 1);
     Query q = flt.rewrite(searcher.getIndexReader());
     HashSet<Term> queryTerms = new HashSet<>();
-    q.extractTerms(queryTerms);
+    searcher.createWeight(q, true).extractTerms(queryTerms);
     assertTrue("Should have variant smythe", queryTerms.contains(new Term("name", "smythe")));
     assertTrue("Should have variant smith", queryTerms.contains(new Term("name", "smith")));
     assertTrue("Should have variant smyth", queryTerms.contains(new Term("name", "smyth")));
@@ -98,7 +98,7 @@ public class FuzzyLikeThisQueryTest exte
     flt.addTerms("jonathin smoth", "name", 0.3f, 1);
     Query q = flt.rewrite(searcher.getIndexReader());
     HashSet<Term> queryTerms = new HashSet<>();
-    q.extractTerms(queryTerms);
+    searcher.createWeight(q, true).extractTerms(queryTerms);
     assertTrue("Should have variant jonathan", queryTerms.contains(new Term("name", "jonathan")));
     assertTrue("Should have variant smith", queryTerms.contains(new Term("name", "smith")));
     TopDocs topDocs = searcher.search(flt, 1);
@@ -116,7 +116,7 @@ public class FuzzyLikeThisQueryTest exte
     // don't fail here just because the field doesn't exits
     Query q = flt.rewrite(searcher.getIndexReader());
     HashSet<Term> queryTerms = new HashSet<>();
-    q.extractTerms(queryTerms);
+    searcher.createWeight(q, true).extractTerms(queryTerms);
     assertTrue("Should have variant jonathan", queryTerms.contains(new Term("name", "jonathan")));
     assertTrue("Should have variant smith", queryTerms.contains(new Term("name", "smith")));
     TopDocs topDocs = searcher.search(flt, 1);
@@ -133,7 +133,7 @@ public class FuzzyLikeThisQueryTest exte
     flt.addTerms("fernando smith", "name", 0.3f, 1);
     Query q = flt.rewrite(searcher.getIndexReader());
     HashSet<Term> queryTerms = new HashSet<>();
-    q.extractTerms(queryTerms);
+    searcher.createWeight(q, true).extractTerms(queryTerms);
     assertTrue("Should have variant smith", queryTerms.contains(new Term("name", "smith")));
     TopDocs topDocs = searcher.search(flt, 1);
     ScoreDoc[] sd = topDocs.scoreDocs;

Modified: lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/composite/CompositeVerifyQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/composite/CompositeVerifyQuery.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/composite/CompositeVerifyQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/composite/CompositeVerifyQuery.java Thu Apr 16 15:56:13 2015
@@ -19,11 +19,9 @@ package org.apache.lucene.spatial.compos
 
 import java.io.IOException;
 import java.util.Map;
-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.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.search.ConstantScoreWeight;
@@ -60,11 +58,6 @@ public class CompositeVerifyQuery extend
   }
 
   @Override
-  public void extractTerms(Set<Term> terms) {
-    indexQuery.extractTerms(terms);
-  }
-
-  @Override
   public boolean equals(Object o) {
     if (this == o) return true;
     if (o == null || getClass() != o.getClass()) return false;

Modified: lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/AssertingQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/AssertingQuery.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/AssertingQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/AssertingQuery.java Thu Apr 16 15:56:13 2015
@@ -47,11 +47,6 @@ public class AssertingQuery extends Quer
   }
 
   @Override
-  public void extractTerms(Set<Term> terms) {
-    in.extractTerms(terms);
-  }
-
-  @Override
   public String toString(String field) {
     return in.toString(field);
   }

Modified: lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/AssertingWeight.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/AssertingWeight.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/AssertingWeight.java (original)
+++ lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/AssertingWeight.java Thu Apr 16 15:56:13 2015
@@ -19,8 +19,10 @@ package org.apache.lucene.search;
 
 import java.io.IOException;
 import java.util.Random;
+import java.util.Set;
 
 import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.Term;
 import org.apache.lucene.util.Bits;
 
 class AssertingWeight extends Weight {
@@ -39,6 +41,11 @@ class AssertingWeight extends Weight {
   }
 
   @Override
+  public void extractTerms(Set<Term> terms) {
+    in.extractTerms(terms);
+  }
+
+  @Override
   public Explanation explain(LeafReaderContext context, int doc) throws IOException {
     return in.explain(context, doc);
   }

Modified: lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/RandomApproximationQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/RandomApproximationQuery.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/RandomApproximationQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/RandomApproximationQuery.java Thu Apr 16 15:56:13 2015
@@ -2,10 +2,13 @@ package org.apache.lucene.search;
 
 import java.io.IOException;
 import java.util.Random;
+import java.util.Set;
 
 import com.carrotsearch.randomizedtesting.generators.RandomInts;
+
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.Term;
 import org.apache.lucene.util.Bits;
 
 /*
@@ -90,6 +93,11 @@ public class RandomApproximationQuery ex
     }
 
     @Override
+    public void extractTerms(Set<Term> terms) {
+      weight.extractTerms(terms);
+    }
+
+    @Override
     public Explanation explain(LeafReaderContext context, int doc) throws IOException {
       return weight.explain(context, doc);
     }

Modified: lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/ShardSearchingTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/ShardSearchingTestBase.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/ShardSearchingTestBase.java (original)
+++ lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/ShardSearchingTestBase.java Thu Apr 16 15:56:13 2015
@@ -228,9 +228,10 @@ public abstract class ShardSearchingTest
 
       @Override
       public Query rewrite(Query original) throws IOException {
-        final Query rewritten = super.rewrite(original);
+        final IndexSearcher localSearcher = new IndexSearcher(getIndexReader());
+        final Weight weight = localSearcher.createNormalizedWeight(original, true);
         final Set<Term> terms = new HashSet<>();
-        rewritten.extractTerms(terms);
+        weight.extractTerms(terms);
 
         // Make a single request to remote nodes for term
         // stats:
@@ -254,7 +255,7 @@ public abstract class ShardSearchingTest
           }
         }
 
-        return rewritten;
+        return weight.getQuery();
       }
 
       @Override

Modified: lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/spans/AssertingSpanQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/spans/AssertingSpanQuery.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/spans/AssertingSpanQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/spans/AssertingSpanQuery.java Thu Apr 16 15:56:13 2015
@@ -38,6 +38,11 @@ public class AssertingSpanQuery extends
   }
 
   @Override
+  protected void extractTerms(Set<Term> terms) {
+    in.extractTerms(terms);
+  }
+
+  @Override
   public Spans getSpans(LeafReaderContext context, Bits acceptDocs, Map<Term,TermContext> termContexts) throws IOException {
     Spans spans = in.getSpans(context, acceptDocs, termContexts);
     if (spans == null) {
@@ -92,11 +97,6 @@ public class AssertingSpanQuery extends
   }
 
   @Override
-  public void extractTerms(Set<Term> terms) {
-    in.extractTerms(terms);
-  }
-
-  @Override
   public Query clone() {
     return new AssertingSpanQuery((SpanQuery) in.clone());
   }

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/schema/LatLonType.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/schema/LatLonType.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/schema/LatLonType.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/schema/LatLonType.java Thu Apr 16 15:56:13 2015
@@ -306,10 +306,6 @@ class SpatialDistanceQuery extends Exten
     return bboxQuery != null ? bboxQuery.rewrite(reader) : this;
   }
 
-  @Override
-  public void extractTerms(Set terms) {}
-
-
   protected class SpatialWeight extends Weight {
     protected IndexSearcher searcher;
     protected float queryNorm;
@@ -327,6 +323,9 @@ class SpatialDistanceQuery extends Exten
     }
 
     @Override
+    public void extractTerms(Set terms) {}
+
+    @Override
     public float getValueForNormalization() throws IOException {
       queryWeight = getBoost();
       return queryWeight * queryWeight;

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/ExportQParserPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/ExportQParserPlugin.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/ExportQParserPlugin.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/ExportQParserPlugin.java Thu Apr 16 15:56:13 2015
@@ -87,10 +87,6 @@ public class ExportQParserPlugin extends
       return this.mainQuery.rewrite(reader);
     }
 
-    public void extractTerms(Set<Term> terms) {
-      this.mainQuery.extractTerms(terms);
-    }
-
     public TopDocsCollector getTopDocsCollector(int len,
                                                 SolrIndexSearcher.QueryCommand cmd,
                                                 IndexSearcher searcher) throws IOException {

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java Thu Apr 16 15:56:13 2015
@@ -204,10 +204,6 @@ class JoinQuery extends Query {
   }
 
   @Override
-  public void extractTerms(Set terms) {
-  }
-
-  @Override
   public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
     return new JoinQueryWeight((SolrIndexSearcher)searcher);
   }
@@ -280,6 +276,9 @@ class JoinQuery extends Query {
     }
 
     @Override
+    public void extractTerms(Set<org.apache.lucene.index.Term> terms) {}
+
+    @Override
     public float getValueForNormalization() throws IOException {
       queryWeight = getBoost();
       return queryWeight * queryWeight;

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java?rev=1674100&r1=1674099&r2=1674100&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java Thu Apr 16 15:56:13 2015
@@ -163,11 +163,6 @@ public class ReRankQParserPlugin extends
 
     }
 
-    public void extractTerms(Set<Term> terms) {
-      this.mainQuery.extractTerms(terms);
-
-    }
-
     public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException{
       return new ReRankWeight(mainQuery, reRankQuery, reRankWeight, searcher, needsScores);
     }
@@ -187,6 +182,12 @@ public class ReRankQParserPlugin extends
       this.mainWeight = mainQuery.createWeight(searcher, needsScores);
     }
 
+    @Override
+    public void extractTerms(Set<Term> terms) {
+      this.mainWeight.extractTerms(terms);
+
+    }
+
     public float getValueForNormalization() throws IOException {
       return mainWeight.getValueForNormalization();
     }



Mime
View raw message