lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r1136702 - in /lucene/dev/branches/branch_3x: ./ lucene/ lucene/backwards/ lucene/backwards/src/test-framework/ lucene/backwards/src/test/ lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ lucene/contrib/grouping/s...
Date Thu, 16 Jun 2011 22:02:58 GMT
Author: uschindler
Date: Thu Jun 16 22:02:57 2011
New Revision: 1136702

URL: http://svn.apache.org/viewvc?rev=1136702&view=rev
Log:
LUCENE-3208: Renamed protected IndexSearcher.createWeight() to expert public method IndexSearcher.createNormalizedWeight()
as this better describes what this method does. The old method is still there for backwards
compatibility. Query.weight() was deprecated and simply delegates to IndexSearcher

Added:
    lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/search/AssertingIndexSearcher.java
      - copied, changed from r1136568, lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/search/AssertingIndexSearcher.java
Modified:
    lucene/dev/branches/branch_3x/   (props changed)
    lucene/dev/branches/branch_3x/lucene/   (props changed)
    lucene/dev/branches/branch_3x/lucene/CHANGES.txt
    lucene/dev/branches/branch_3x/lucene/backwards/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/src/test/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/src/test-framework/   (props changed)
    lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java
    lucene/dev/branches/branch_3x/lucene/contrib/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/BufferedDeletesStream.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/IndexSearcher.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/MultiSearcher.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/Query.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/QueryWrapperFilter.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/Searcher.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/function/CustomScoreQuery.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java
    lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/search/QueryUtils.java
    lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/JustCompileSearch.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestTermScorer.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestTopDocsMerge.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/spans/TestSpans.java
    lucene/dev/branches/branch_3x/solr/   (props changed)
    lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/search/function/BoostedQuery.java
    lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/search/function/QueryValueSource.java

Modified: lucene/dev/branches/branch_3x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/CHANGES.txt?rev=1136702&r1=1136701&r2=1136702&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_3x/lucene/CHANGES.txt Thu Jun 16 22:02:57 2011
@@ -15,6 +15,11 @@ Changes in backwards compatibility polic
   Comparable; FieldDoc.fields also changed from Comparable[] to
   Object[] (Uwe Schindler, Mike McCandless)
 
+* LUCENE-3208: Made deprecated methods Query.weight(Searcher) and
+  Searcher.createWeight() final to prevent override. If you have
+  overridden one of these methods, cut over to the non-deprecated
+  implementation. (Uwe Schindler, Robert Muir, Yonik Seeley)
+
 Changes in runtime behavior
 
 * LUCENE-2834: the hash used to compute the lock file name when the
@@ -53,6 +58,15 @@ Bug fixes
   ArrayIndexOutOfBoundsException (selckin, Robert Muir, Mike
   McCandless)
 
+API Changes
+
+* LUCENE-3208: Renamed protected IndexSearcher.createWeight() to expert
+  public method IndexSearcher.createNormalizedWeight() as this better describes
+  what this method does. The old method is still there for backwards
+  compatibility. Query.weight() was deprecated and simply delegates to
+  IndexSearcher. Both deprecated methods will be removed in Lucene 4.0.
+  (Uwe Schindler, Robert Muir, Yonik Seeley)
+
 Optimizations
 
 * LUCENE-1736: DateTools.java general improvements. 

Modified: lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java?rev=1136702&r1=1136701&r2=1136702&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java
Thu Jun 16 22:02:57 2011
@@ -112,7 +112,7 @@ public abstract class ReadTask extends P
       if (numHits > 0) {
         if (withCollector() == false) {
           if (sort != null) {
-            Weight w = q.weight(searcher);
+            Weight w = searcher.createNormalizedWeight(q);
             TopFieldCollector collector = TopFieldCollector.create(sort, numHits,
                                                                    true, withScore(),
                                                                    withMaxScore(),

Modified: lucene/dev/branches/branch_3x/lucene/contrib/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java?rev=1136702&r1=1136701&r2=1136702&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java
Thu Jun 16 22:02:57 2011
@@ -908,7 +908,7 @@ public class TestGrouping extends Lucene
       System.out.println("TEST: " + shardState.subSearchers.length + " shards: " + Arrays.toString(shardState.subSearchers));
     }
     // Run 1st pass collector to get top groups per shard
-    final Weight w = query.weight(topSearcher);
+    final Weight w = topSearcher.createNormalizedWeight(query);
     final List<Collection<SearchGroup<String>>> shardGroups = new ArrayList<Collection<SearchGroup<String>>>();
     for(int shardIDX=0;shardIDX<shardState.subSearchers.length;shardIDX++) {
       final TermFirstPassGroupingCollector c = new TermFirstPassGroupingCollector("group",
groupSort, groupOffset+topNGroups);

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/BufferedDeletesStream.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/BufferedDeletesStream.java?rev=1136702&r1=1136701&r2=1136702&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/BufferedDeletesStream.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/BufferedDeletesStream.java
Thu Jun 16 22:02:57 2011
@@ -27,10 +27,10 @@ import java.util.Collections;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
 
-import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.DocIdSet;
+import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.search.Query;
-import org.apache.lucene.search.Scorer;
-import org.apache.lucene.search.Weight;
+import org.apache.lucene.search.QueryWrapperFilter;
 
 /* Tracks the stream of {@link BuffereDeletes}.
  * When DocumensWriter flushes, its buffered
@@ -377,16 +377,16 @@ class BufferedDeletesStream {
   // Delete by query
   private synchronized long applyQueryDeletes(Iterable<QueryAndLimit> queriesIter,
SegmentReader reader) throws IOException {
     long delCount = 0;
-    IndexSearcher searcher = new IndexSearcher(reader);
-    try {
-      for (QueryAndLimit ent : queriesIter) {
-        Query query = ent.query;
-        int limit = ent.limit;
-        Weight weight = query.weight(searcher);
-        Scorer scorer = weight.scorer(reader, true, false);
-        if (scorer != null) {
+
+    for (QueryAndLimit ent : queriesIter) {
+      Query query = ent.query;
+      int limit = ent.limit;
+      final DocIdSet docs = new QueryWrapperFilter(query).getDocIdSet(reader);
+      if (docs != null) {
+        final DocIdSetIterator it = docs.iterator();
+        if (it != null) {
           while(true)  {
-            int doc = scorer.nextDoc();
+            int doc = it.nextDoc();
             if (doc >= limit)
               break;
 
@@ -400,8 +400,6 @@ class BufferedDeletesStream {
           }
         }
       }
-    } finally {
-      searcher.close();
     }
 
     return delCount;

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/IndexSearcher.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/IndexSearcher.java?rev=1136702&r1=1136701&r2=1136702&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/IndexSearcher.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/IndexSearcher.java
Thu Jun 16 22:02:57 2011
@@ -79,9 +79,6 @@ public class IndexSearcher extends Searc
   private final ExecutorService executor;
   protected final IndexSearcher[] subSearchers;
 
-  /** The Similarity implementation used by this searcher. */
-  private Similarity similarity = Similarity.getDefault();
-
   /** Creates a searcher searching the index in the named
    *  directory, with readOnly=true
    * @param path directory where IndexReader will be opened
@@ -257,12 +254,12 @@ public class IndexSearcher extends Searc
    */
   @Override
   public void setSimilarity(Similarity similarity) {
-    this.similarity = similarity;
+    super.setSimilarity(similarity);
   }
 
   @Override
   public Similarity getSimilarity() {
-    return similarity;
+    return super.getSimilarity();
   }
 
   /**
@@ -298,7 +295,7 @@ public class IndexSearcher extends Searc
   @Override
   public TopDocs search(Query query, Filter filter, int n)
     throws IOException {
-    return search(createWeight(query), filter, n);
+    return search(createNormalizedWeight(query), filter, n);
   }
 
   /** Lower-level search API.
@@ -320,7 +317,7 @@ public class IndexSearcher extends Searc
   @Override
   public void search(Query query, Filter filter, Collector results)
     throws IOException {
-    search(createWeight(query), filter, results);
+    search(createNormalizedWeight(query), filter, results);
   }
 
   /** Lower-level search API.
@@ -339,7 +336,7 @@ public class IndexSearcher extends Searc
   @Override
   public void search(Query query, Collector results)
     throws IOException {
-    search(createWeight(query), null, results);
+    search(createNormalizedWeight(query), null, results);
   }
   
   /** Search implementation with arbitrary sorting.  Finds
@@ -356,7 +353,7 @@ public class IndexSearcher extends Searc
   @Override
   public TopFieldDocs search(Query query, Filter filter, int n,
                              Sort sort) throws IOException {
-    return search(createWeight(query), filter, n, sort);
+    return search(createNormalizedWeight(query), filter, n, sort);
   }
 
   /**
@@ -370,7 +367,7 @@ public class IndexSearcher extends Searc
   @Override
   public TopFieldDocs search(Query query, int n,
                              Sort sort) throws IOException {
-    return search(createWeight(query), null, n, sort);
+    return search(createNormalizedWeight(query), null, n, sort);
   }
 
   /** Expert: Low-level search implementation.  Finds the top <code>n</code>
@@ -606,7 +603,7 @@ public class IndexSearcher extends Searc
    */
   @Override
   public Explanation explain(Query query, int doc) throws IOException {
-    return explain(createWeight(query), doc);
+    return explain(createNormalizedWeight(query), doc);
   }
 
   /** Expert: low-level implementation method
@@ -654,15 +651,16 @@ public class IndexSearcher extends Searc
   }
 
   /**
-   * creates a weight for <code>query</code>
-   * @return new weight
+   * Creates a normalized weight for a top-level {@link Query}.
+   * The query is rewritten by this method and {@link Query#createWeight} called,
+   * afterwards the {@link Weight} is normalized. The returned {@code Weight}
+   * can then directly be used to get a {@link Scorer}.
+   * @lucene.internal
    */
-  @Override
-  protected Weight createWeight(Query query) throws IOException {
-    return query.weight(this);
+  public Weight createNormalizedWeight(Query query) throws IOException {
+    return super.createNormalizedWeight(query);
   }
 
-
   /**
    * A thread subclass for searching a single searchable 
    */

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/MultiSearcher.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/MultiSearcher.java?rev=1136702&r1=1136701&r2=1136702&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/MultiSearcher.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/MultiSearcher.java
Thu Jun 16 22:02:57 2011
@@ -310,7 +310,7 @@ public class MultiSearcher extends Searc
    * @return rewritten queries
    */
   @Override
-  protected Weight createWeight(Query original) throws IOException {
+  public Weight createNormalizedWeight(Query original) throws IOException {
     // step 1
     final Query rewrittenQuery = rewrite(original);
 
@@ -325,7 +325,7 @@ public class MultiSearcher extends Searc
     final int numDocs = maxDoc();
     final CachedDfSource cacheSim = new CachedDfSource(dfMap, numDocs, getSimilarity());
 
-    return rewrittenQuery.weight(cacheSim);
+    return cacheSim.createNormalizedWeight(rewrittenQuery);
   }
   /**
    * Collects the document frequency for the given terms form all searchables

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/Query.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/Query.java?rev=1136702&r1=1136701&r2=1136702&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/Query.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/Query.java Thu
Jun 16 22:02:57 2011
@@ -94,17 +94,13 @@ public abstract class Query implements j
   }
 
   /**
-   * Expert: Constructs and initializes a Weight for a top-level query.
+   * Expert: Constructs and initializes a Weight for a <b>top-level</b> query.
+   * @deprecated never ever use this method in {@link Weight} implementations.
+   * Subclasses of {@code Query} should use {@link #createWeight}, instead.
    */
-  public Weight weight(Searcher searcher) throws IOException {
-    Query query = searcher.rewrite(this);
-    Weight weight = query.createWeight(searcher);
-    float sum = weight.sumOfSquaredWeights();
-    float norm = getSimilarity(searcher).queryNorm(sum);
-    if (Float.isInfinite(norm) || Float.isNaN(norm))
-      norm = 1.0f;
-    weight.normalize(norm);
-    return weight;
+  @Deprecated
+  public final Weight weight(Searcher searcher) throws IOException {
+    return searcher.createNormalizedWeight(this);
   }
   
 

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/QueryWrapperFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/QueryWrapperFilter.java?rev=1136702&r1=1136701&r2=1136702&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/QueryWrapperFilter.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/QueryWrapperFilter.java
Thu Jun 16 22:02:57 2011
@@ -44,7 +44,7 @@ public class QueryWrapperFilter extends 
 
   @Override
   public DocIdSet getDocIdSet(final IndexReader reader) throws IOException {
-    final Weight weight = query.weight(new IndexSearcher(reader));
+    final Weight weight = new IndexSearcher(reader).createNormalizedWeight(query);
     return new DocIdSet() {
       @Override
       public DocIdSetIterator iterator() throws IOException {

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/Searcher.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/Searcher.java?rev=1136702&r1=1136701&r2=1136702&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/Searcher.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/Searcher.java Thu
Jun 16 22:02:57 2011
@@ -50,7 +50,7 @@ public abstract class Searcher implement
    */
   public TopFieldDocs search(Query query, Filter filter, int n,
                              Sort sort) throws IOException {
-    return search(createWeight(query), filter, n, sort);
+    return search(createNormalizedWeight(query), filter, n, sort);
   }
 
   /**
@@ -63,7 +63,7 @@ public abstract class Searcher implement
    */
   public TopFieldDocs search(Query query, int n,
                              Sort sort) throws IOException {
-    return search(createWeight(query), null, n, sort);
+    return search(createNormalizedWeight(query), null, n, sort);
   }
 
   /** Lower-level search API.
@@ -81,7 +81,7 @@ public abstract class Searcher implement
   */
  public void search(Query query, Collector results)
    throws IOException {
-   search(createWeight(query), null, results);
+   search(createNormalizedWeight(query), null, results);
  }
 
   /** Lower-level search API.
@@ -102,7 +102,7 @@ public abstract class Searcher implement
    */
   public void search(Query query, Filter filter, Collector results)
   throws IOException {
-    search(createWeight(query), filter, results);
+    search(createNormalizedWeight(query), filter, results);
   }
 
   /** Finds the top <code>n</code>
@@ -112,7 +112,7 @@ public abstract class Searcher implement
    */
   public TopDocs search(Query query, Filter filter, int n)
     throws IOException {
-    return search(createWeight(query), filter, n);
+    return search(createNormalizedWeight(query), filter, n);
   }
 
   /** Finds the top <code>n</code>
@@ -134,7 +134,7 @@ public abstract class Searcher implement
    * entire index.
    */
   public Explanation explain(Query query, int doc) throws IOException {
-    return explain(createWeight(query), doc);
+    return explain(createNormalizedWeight(query), doc);
   }
 
   /** The Similarity implementation used by this searcher. */
@@ -157,11 +157,35 @@ public abstract class Searcher implement
   }
 
   /**
-   * creates a weight for <code>query</code>
-   * @return new weight
-   */
-  protected Weight createWeight(Query query) throws IOException {
-    return query.weight(this);
+   * Creates a normalized weight for a top-level {@link Query}.
+   * The query is rewritten by this method and {@link Query#createWeight} called,
+   * afterwards the {@link Weight} is normalized. The returned {@code Weight}
+   * can then directly be used to get a {@link Scorer}.
+   * @lucene.internal
+   */
+  public Weight createNormalizedWeight(Query query) throws IOException {
+    query = rewrite(query);
+    Weight weight = query.createWeight(this);
+    float sum = weight.sumOfSquaredWeights();
+    // this is a hack for backwards compatibility:
+    float norm = query.getSimilarity(this).queryNorm(sum);
+    if (Float.isInfinite(norm) || Float.isNaN(norm))
+      norm = 1.0f;
+    weight.normalize(norm);
+    return weight;
+  }
+  
+  /**
+   * Expert: Creates a normalized weight for a top-level {@link Query}.
+   * The query is rewritten by this method and {@link Query#createWeight} called,
+   * afterwards the {@link Weight} is normalized. The returned {@code Weight}
+   * can then directly be used to get a {@link Scorer}.
+   * @deprecated never ever use this method in {@link Weight} implementations.
+   * Subclasses of Searcher should use {@link #createNormalizedWeight}, instead.
+   */
+  @Deprecated
+  protected final Weight createWeight(Query query) throws IOException {
+    return createNormalizedWeight(query);
   }
 
   // inherit javadoc

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/function/CustomScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/function/CustomScoreQuery.java?rev=1136702&r1=1136701&r2=1136702&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/function/CustomScoreQuery.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/function/CustomScoreQuery.java
Thu Jun 16 22:02:57 2011
@@ -189,7 +189,7 @@ public class CustomScoreQuery extends Qu
 
     public CustomWeight(Searcher searcher) throws IOException {
       this.similarity = getSimilarity(searcher);
-      this.subQueryWeight = subQuery.weight(searcher);
+      this.subQueryWeight = subQuery.createWeight(searcher);
       this.valSrcWeights = new Weight[valSrcQueries.length];
       for(int i = 0; i < valSrcQueries.length; i++) {
         this.valSrcWeights[i] = valSrcQueries[i].createWeight(searcher);

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java?rev=1136702&r1=1136701&r2=1136702&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java
Thu Jun 16 22:02:57 2011
@@ -107,11 +107,6 @@ public class FieldMaskingSpanQuery exten
   }
 
   @Override
-  public Similarity getSimilarity(Searcher searcher) {
-    return maskedQuery.getSimilarity(searcher);
-  }
-
-  @Override
   public Query rewrite(IndexReader reader) throws IOException {
     FieldMaskingSpanQuery clone = null;
 

Copied: lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/search/AssertingIndexSearcher.java
(from r1136568, lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/search/AssertingIndexSearcher.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/search/AssertingIndexSearcher.java?p2=lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/search/AssertingIndexSearcher.java&p1=lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/search/AssertingIndexSearcher.java&r1=1136568&r2=1136702&rev=1136702&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/search/AssertingIndexSearcher.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/search/AssertingIndexSearcher.java
Thu Jun 16 22:02:57 2011
@@ -21,8 +21,6 @@ import java.util.concurrent.ExecutorServ
 import java.io.IOException;
 
 import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.IndexReader.AtomicReaderContext;
-import org.apache.lucene.index.IndexReader.ReaderContext;
 
 /** 
  * Helper class that adds some extra checks to ensure correct
@@ -34,57 +32,58 @@ public class AssertingIndexSearcher exte
     super(r);
   }
   
-  public  AssertingIndexSearcher(ReaderContext context) {
-    super(context);
-  }
-  
   public  AssertingIndexSearcher(IndexReader r, ExecutorService ex) {
     super(r, ex);
   }
   
-  public  AssertingIndexSearcher(ReaderContext context, ExecutorService ex) {
-    super(context, ex);
+  // not anonymous because else not serializable (compare trunk)
+  private static final class UnmodifiableWeight extends Weight {
+    private final Weight w;
+    
+    UnmodifiableWeight(Weight w) {
+      this.w = w;
+    }
+  
+    @Override
+    public Explanation explain(IndexReader reader, int doc) throws IOException {
+      return w.explain(reader, doc);
+    }
+
+    @Override
+    public Query getQuery() {
+      return w.getQuery();
+    }
+
+    @Override
+    public float getValue() {
+      return w.getValue();
+    }
+
+    @Override
+    public void normalize(float norm) {
+      throw new IllegalStateException("Weight already normalized.");
+    }
+
+    @Override
+    public Scorer scorer(IndexReader reader, boolean scoreDocsInOrder, boolean topScorer)
throws IOException {
+      return w.scorer(reader, scoreDocsInOrder, topScorer);
+    }
+
+    @Override
+    public float sumOfSquaredWeights() throws IOException {
+      throw new IllegalStateException("Weight already normalized.");
+    }
+
+    @Override
+    public boolean scoresDocsOutOfOrder() {
+      return w.scoresDocsOutOfOrder();
+    }
   }
   
   /** Ensures, that the returned {@code Weight} is not normalized again, which may produce
wrong scores. */
   @Override
   public Weight createNormalizedWeight(Query query) throws IOException {
     final Weight w = super.createNormalizedWeight(query);
-    return new Weight() {
-      @Override
-      public Explanation explain(AtomicReaderContext context, int doc) throws IOException
{
-        return w.explain(context, doc);
-      }
-
-      @Override
-      public Query getQuery() {
-        return w.getQuery();
-      }
-
-      @Override
-      public float getValue() {
-        return w.getValue();
-      }
-
-      @Override
-      public void normalize(float norm) {
-        throw new IllegalStateException("Weight already normalized.");
-      }
-
-      @Override
-      public Scorer scorer(AtomicReaderContext context, ScorerContext scorerContext) throws
IOException {
-        return w.scorer(context, scorerContext);
-      }
-
-      @Override
-      public float sumOfSquaredWeights() throws IOException {
-        throw new IllegalStateException("Weight already normalized.");
-      }
-
-      @Override
-      public boolean scoresDocsOutOfOrder() {
-        return w.scoresDocsOutOfOrder();
-      }
-    };
+    return new UnmodifiableWeight(w);
   }
 }

Modified: lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/search/QueryUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/search/QueryUtils.java?rev=1136702&r1=1136701&r2=1136702&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/search/QueryUtils.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/search/QueryUtils.java
Thu Jun 16 22:02:57 2011
@@ -241,7 +241,7 @@ public class QueryUtils {
    * @throws IOException if serialization check fail. 
    */
   private static void checkSerialization(Query q, Searcher s) throws IOException {
-    Weight w = q.weight(s);
+    Weight w = s.createNormalizedWeight(q);
     try {
       ByteArrayOutputStream bos = new ByteArrayOutputStream();
       ObjectOutputStream oos = new ObjectOutputStream(bos);
@@ -268,7 +268,7 @@ public class QueryUtils {
   public static void checkSkipTo(final Query q, final IndexSearcher s) throws IOException
{
     //System.out.println("Checking "+q);
     
-    if (q.weight(s).scoresDocsOutOfOrder()) return;  // in this case order of skipTo() might
differ from that of next().
+    if (s.createNormalizedWeight(q).scoresDocsOutOfOrder()) return;  // in this case order
of skipTo() might differ from that of next().
 
     final int skip_op = 0;
     final int next_op = 1;
@@ -311,7 +311,7 @@ public class QueryUtils {
             lastDoc[0] = doc;
             try {
               if (scorer == null) {
-                Weight w = q.weight(s);
+                Weight w = s.createNormalizedWeight(q);
                 scorer = w.scorer(reader, true, false);
               }
               
@@ -355,7 +355,7 @@ public class QueryUtils {
             // previous reader, hits NO_MORE_DOCS
             if (lastReader[0] != null) {
               final IndexReader previousReader = lastReader[0];
-              Weight w = q.weight(new IndexSearcher(previousReader));
+              Weight w = new IndexSearcher(previousReader).createNormalizedWeight(q);
               Scorer scorer = w.scorer(previousReader, true, false);
               if (scorer != null) {
                 boolean more = scorer.advance(lastDoc[0] + 1) != DocIdSetIterator.NO_MORE_DOCS;
@@ -377,7 +377,7 @@ public class QueryUtils {
           // confirm that skipping beyond the last doc, on the
           // previous reader, hits NO_MORE_DOCS
           final IndexReader previousReader = lastReader[0];
-          Weight w = q.weight(new IndexSearcher(previousReader));
+          Weight w = new IndexSearcher(previousReader).createNormalizedWeight(q);
           Scorer scorer = w.scorer(previousReader, true, false);
           if (scorer != null) {
             boolean more = scorer.advance(lastDoc[0] + 1) != DocIdSetIterator.NO_MORE_DOCS;
@@ -408,7 +408,7 @@ public class QueryUtils {
         try {
           
           for (int i=lastDoc[0]+1; i<=doc; i++) {
-            Weight w = q.weight(s);
+            Weight w = s.createNormalizedWeight(q);
             Scorer scorer = w.scorer(reader, true, false);
             Assert.assertTrue("query collected "+doc+" but skipTo("+i+") says no more docs!",scorer.advance(i)
!= DocIdSetIterator.NO_MORE_DOCS);
             Assert.assertEquals("query collected "+doc+" but skipTo("+i+") got to "+scorer.docID(),doc,scorer.docID());
@@ -428,8 +428,9 @@ public class QueryUtils {
         // previous reader, hits NO_MORE_DOCS
         if (lastReader[0] != null) {
           final IndexReader previousReader = lastReader[0];
-          Weight w = q.weight(new IndexSearcher(previousReader));
+          Weight w = new IndexSearcher(previousReader).createNormalizedWeight(q);
           Scorer scorer = w.scorer(previousReader, true, false);
+
           if (scorer != null) {
             boolean more = scorer.advance(lastDoc[0] + 1) != DocIdSetIterator.NO_MORE_DOCS;
             Assert.assertFalse("query's last doc was "+ lastDoc[0] +" but skipTo("+(lastDoc[0]+1)+")
got to "+scorer.docID(),more);
@@ -449,7 +450,7 @@ public class QueryUtils {
       // confirm that skipping beyond the last doc, on the
       // previous reader, hits NO_MORE_DOCS
       final IndexReader previousReader = lastReader[0];
-      Weight w = q.weight(new IndexSearcher(previousReader));
+      Weight w = new IndexSearcher(previousReader).createNormalizedWeight(q);
       Scorer scorer = w.scorer(previousReader, true, false);
       if (scorer != null) {
         boolean more = scorer.advance(lastDoc[0] + 1) != DocIdSetIterator.NO_MORE_DOCS;

Modified: lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java?rev=1136702&r1=1136701&r2=1136702&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java
Thu Jun 16 22:02:57 2011
@@ -49,6 +49,7 @@ import org.apache.lucene.index.SlowMulti
 import org.apache.lucene.index.TieredMergePolicy;
 import org.apache.lucene.search.BooleanQuery;
 import org.apache.lucene.search.FieldCache.CacheEntry;
+import org.apache.lucene.search.AssertingIndexSearcher;
 import org.apache.lucene.search.FieldCache;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.store.Directory;
@@ -1097,13 +1098,11 @@ public abstract class LuceneTestCase ext
    * with one that returns null for getSequentialSubReaders.
    */
   public static IndexSearcher newSearcher(IndexReader r, boolean maybeWrap) throws IOException
{
-
     if (random.nextBoolean()) {
       if (maybeWrap && rarely()) {
-        return new IndexSearcher(new SlowMultiReaderWrapper(r));
-      } else {
-        return new IndexSearcher(r);
+        r = new SlowMultiReaderWrapper(r);
       }
+      return new AssertingIndexSearcher(r);
     } else {
       int threads = 0;
       final ExecutorService ex = (random.nextBoolean()) ? null 
@@ -1112,22 +1111,26 @@ public abstract class LuceneTestCase ext
       if (ex != null && VERBOSE) {
         System.out.println("NOTE: newSearcher using ExecutorService with " + threads + "
threads");
       }
-      return new IndexSearcher(r, ex) {
+      return new AssertingIndexSearcher(r, ex) {
         @Override
         public void close() throws IOException {
           super.close();
-          if (ex != null) {
-            ex.shutdown();
-            try {
-              ex.awaitTermination(1000, TimeUnit.MILLISECONDS);
-            } catch (InterruptedException e) {
-              e.printStackTrace();
-            }
-          }
+          shutdownExecutorService(ex);
         }
       };
     }
   }
+  
+  static void shutdownExecutorService(ExecutorService ex) {
+    if (ex != null) {
+      ex.shutdown();
+      try {
+        ex.awaitTermination(1000, TimeUnit.MILLISECONDS);
+      } catch (InterruptedException e) {
+        e.printStackTrace();
+      }
+    }
+  }
 
   public String getName() {
     return this.name;

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/JustCompileSearch.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/JustCompileSearch.java?rev=1136702&r1=1136701&r2=1136702&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/JustCompileSearch.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/JustCompileSearch.java
Thu Jun 16 22:02:57 2011
@@ -41,7 +41,7 @@ final class JustCompileSearch {
   static final class JustCompileSearcher extends Searcher {
 
     @Override
-    protected Weight createWeight(Query query) throws IOException {
+    public Weight createNormalizedWeight(Query query) throws IOException {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);
     }
     

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java?rev=1136702&r1=1136701&r2=1136702&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java
Thu Jun 16 22:02:57 2011
@@ -167,7 +167,7 @@ public class TestDisjunctionMaxQuery ext
     
     QueryUtils.check(random, dq, s);
     
-    final Weight dw = dq.weight(s);
+    final Weight dw = s.createNormalizedWeight(dq);
     IndexReader sub = s.getIndexReader().getSequentialSubReaders() == null ?
         s.getIndexReader() : s.getIndexReader().getSequentialSubReaders()[0];
     final Scorer ds = dw.scorer(sub, true, false);
@@ -184,8 +184,8 @@ public class TestDisjunctionMaxQuery ext
     dq.add(tq("dek", "DOES_NOT_EXIST"));
     
     QueryUtils.check(random, dq, s);
-    
-    final Weight dw = dq.weight(s);
+
+    final Weight dw = s.createNormalizedWeight(dq);
     IndexReader sub = s.getIndexReader().getSequentialSubReaders() == null ?
         s.getIndexReader() : s.getIndexReader().getSequentialSubReaders()[0];
     final Scorer ds = dw.scorer(sub, true, false);

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestTermScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestTermScorer.java?rev=1136702&r1=1136701&r2=1136702&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestTermScorer.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestTermScorer.java
Thu Jun 16 22:02:57 2011
@@ -71,7 +71,7 @@ public class TestTermScorer extends Luce
     Term allTerm = new Term(FIELD, "all");
     TermQuery termQuery = new TermQuery(allTerm);
     
-    Weight weight = termQuery.weight(indexSearcher);
+    Weight weight = indexSearcher.createNormalizedWeight(termQuery);
     IndexReader sub = indexSearcher.getIndexReader().getSequentialSubReaders() == null ?
                 indexSearcher.getIndexReader() : indexSearcher.getIndexReader().getSequentialSubReaders()[0];
     Scorer ts = weight.scorer(sub, true, true);
@@ -133,7 +133,7 @@ public class TestTermScorer extends Luce
     Term allTerm = new Term(FIELD, "all");
     TermQuery termQuery = new TermQuery(allTerm);
     
-    Weight weight = termQuery.weight(indexSearcher);
+    Weight weight = indexSearcher.createNormalizedWeight(termQuery);
     
     IndexReader sub = indexSearcher.getIndexReader().getSequentialSubReaders() == null ?
         indexSearcher.getIndexReader() : indexSearcher.getIndexReader().getSequentialSubReaders()[0];
@@ -153,7 +153,7 @@ public class TestTermScorer extends Luce
     Term allTerm = new Term(FIELD, "all");
     TermQuery termQuery = new TermQuery(allTerm);
     
-    Weight weight = termQuery.weight(indexSearcher);
+    Weight weight = indexSearcher.createNormalizedWeight(termQuery);
     
     IndexReader sub = indexSearcher.getIndexReader().getSequentialSubReaders() == null ?

         indexSearcher.getIndexReader() : indexSearcher.getIndexReader().getSequentialSubReaders()[0];

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestTopDocsMerge.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestTopDocsMerge.java?rev=1136702&r1=1136701&r2=1136702&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestTopDocsMerge.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestTopDocsMerge.java
Thu Jun 16 22:02:57 2011
@@ -191,7 +191,7 @@ public class TestTopDocsMerge extends Lu
       }
 
       // ... then all shards:
-      final Weight w = query.weight(searcher);
+      final Weight w = searcher.createNormalizedWeight(query);
 
       final TopDocs[] shardHits = new TopDocs[subSearchers.length];
       for(int shardIDX=0;shardIDX<subSearchers.length;shardIDX++) {

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java?rev=1136702&r1=1136701&r2=1136702&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java
Thu Jun 16 22:02:57 2011
@@ -167,17 +167,18 @@ public class TestNearSpansOrdered extend
    */
   public void testSpanNearScorerSkipTo1() throws Exception {
     SpanNearQuery q = makeQuery();
-    Weight w = q.weight(searcher);
+    Weight w = searcher.createNormalizedWeight(q);
     Scorer s = w.scorer(searcher.getIndexReader(), true, false);
     assertEquals(1, s.advance(1));
   }
+  
   /**
    * not a direct test of NearSpans, but a demonstration of how/when
    * this causes problems
    */
   public void testSpanNearScorerExplain() throws Exception {
     SpanNearQuery q = makeQuery();
-    Explanation e = q.weight(searcher).explain(searcher.getIndexReader(), 1);
+    Explanation e = searcher.explain(q, 1);
     assertTrue("Scorer explanation value for doc#1 isn't positive: "
                + e.toString(),
                0.0f < e.getValue());

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/spans/TestSpans.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/spans/TestSpans.java?rev=1136702&r1=1136701&r2=1136702&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/spans/TestSpans.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/spans/TestSpans.java
Thu Jun 16 22:02:57 2011
@@ -420,7 +420,7 @@ public class TestSpans extends LuceneTes
       }
       };
 
-    Scorer spanScorer = snq.weight(searcher).scorer(searcher.getIndexReader(), true, false);
+    Scorer spanScorer = searcher.createNormalizedWeight(snq).scorer(searcher.getIndexReader(),
true, false);
 
     assertTrue("first doc", spanScorer.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
     assertEquals("first doc number", spanScorer.docID(), 11);

Modified: lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/search/function/BoostedQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/search/function/BoostedQuery.java?rev=1136702&r1=1136701&r2=1136702&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/search/function/BoostedQuery.java
(original)
+++ lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/search/function/BoostedQuery.java
Thu Jun 16 22:02:57 2011
@@ -67,7 +67,7 @@ public class BoostedQuery extends Query 
 
     public BoostedWeight(Searcher searcher) throws IOException {
       this.searcher = searcher;
-      this.qWeight = q.weight(searcher);
+      this.qWeight = q.createWeight(searcher);
       this.context = boostVal.newContext();
       boostVal.createWeight(context,searcher);
     }

Modified: lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/search/function/QueryValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/search/function/QueryValueSource.java?rev=1136702&r1=1136701&r2=1136702&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/search/function/QueryValueSource.java
(original)
+++ lucene/dev/branches/branch_3x/solr/src/java/org/apache/solr/search/function/QueryValueSource.java
Thu Jun 16 22:02:57 2011
@@ -63,7 +63,7 @@ public class QueryValueSource extends Va
 
   @Override
   public void createWeight(Map context, Searcher searcher) throws IOException {
-    Weight w = q.weight(searcher);
+    Weight w = searcher.createNormalizedWeight(q);
     context.put(this, w);
   }
 }
@@ -87,7 +87,7 @@ class QueryDocValues extends DocValues {
     this.reader = reader;
     this.q = q;
     this.defVal = defVal;
-    weight = w!=null ? w : q.weight(new IndexSearcher(reader));
+    weight = w!=null ? w : new IndexSearcher(reader).createNormalizedWeight(q);
   }
 
   @Override



Mime
View raw message