lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r764551 [3/3] - in /lucene/java/trunk: ./ contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ contrib/miscellaneous/src/test/org/apache/lucene/index/ contrib/miscellaneous/src/test/org/apache/lucene/misc/ contrib/spatial/sr...
Date Mon, 13 Apr 2009 18:33:58 GMT
Added: lucene/java/trunk/src/test/org/apache/lucene/search/JustCompileSearch.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/JustCompileSearch.java?rev=764551&view=auto
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/JustCompileSearch.java (added)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/JustCompileSearch.java Mon Apr 13 18:33:56 2009
@@ -0,0 +1,580 @@
+package org.apache.lucene.search;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.FieldSelector;
+import org.apache.lucene.index.CorruptIndexException;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.index.TermPositions;
+import org.apache.lucene.util.PriorityQueue;
+
+/**
+ * Holds all implementations of classes in the o.a.l.search package as a
+ * back-compatibility test. It does not run any tests per-se, however if 
+ * someone adds a method to an interface or abstract method to an abstract
+ * class, one of the implementations here will fail to compile and so we know
+ * back-compat policy was violated.
+ */
+final class JustCompileSearch {
+
+  private static final String UNSUPPORTED_MSG = "unsupported: used for back-compat testing only !";
+
+  static final class JustCompileSearchable implements Searchable {
+
+    public void close() throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public Document doc(int i) throws CorruptIndexException, IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public Document doc(int n, FieldSelector fieldSelector)
+        throws CorruptIndexException, IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public int docFreq(Term term) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public int[] docFreqs(Term[] terms) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public Explanation explain(Weight weight, int doc) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public int maxDoc() throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public Query rewrite(Query query) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public void search(Weight weight, Filter filter, HitCollector results)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public void search(Weight weight, Filter filter, Collector collector)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public TopDocs search(Weight weight, Filter filter, int n)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public TopFieldDocs search(Weight weight, Filter filter, int n, Sort sort)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+  }
+
+  static final class JustCompileSearcher extends Searcher {
+
+    public void close() throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public Document doc(int i) throws CorruptIndexException, IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public int docFreq(Term term) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public Explanation explain(Weight weight, int doc) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public int maxDoc() throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public Query rewrite(Query query) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public void search(Weight weight, Filter filter, HitCollector results)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public void search(Weight weight, Filter filter, Collector results)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public TopDocs search(Weight weight, Filter filter, int n)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public TopFieldDocs search(Weight weight, Filter filter, int n, Sort sort)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public Document doc(int n, FieldSelector fieldSelector)
+        throws CorruptIndexException, IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+  
+  static final class JustCompileCollector extends Collector {
+
+    public void collect(int doc) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public void setNextReader(IndexReader reader, int docBase)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public void setScorer(Scorer scorer) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+  
+  static final class JustCompileDocIdSet extends DocIdSet {
+
+    public DocIdSetIterator iterator() throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+
+  static final class JustCompileDocIdSetIterator extends DocIdSetIterator {
+
+    public int doc() {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public boolean next() throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public boolean skipTo(int target) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+  
+  static final class JustCompileFieldCache implements FieldCache {
+
+    public Object getAuto(IndexReader reader, String field) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public byte[] getBytes(IndexReader reader, String field) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public byte[] getBytes(IndexReader reader, String field, ByteParser parser)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    /** @deprecated */
+    public Comparable[] getCustom(IndexReader reader, String field,
+        SortComparator comparator) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public float[] getFloats(IndexReader reader, String field)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public float[] getFloats(IndexReader reader, String field,
+        FloatParser parser) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public int[] getInts(IndexReader reader, String field) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public int[] getInts(IndexReader reader, String field, IntParser parser)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public short[] getShorts(IndexReader reader, String field)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public short[] getShorts(IndexReader reader, String field,
+        ShortParser parser) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public StringIndex getStringIndex(IndexReader reader, String field)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public String[] getStrings(IndexReader reader, String field)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+
+  static final class JustCompileExtendedFieldCache implements ExtendedFieldCache {
+
+    public double[] getDoubles(IndexReader reader, String field)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public double[] getDoubles(IndexReader reader, String field,
+        DoubleParser parser) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public long[] getLongs(IndexReader reader, String field) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public long[] getLongs(IndexReader reader, String field, LongParser parser)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public Object getAuto(IndexReader reader, String field) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public byte[] getBytes(IndexReader reader, String field) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public byte[] getBytes(IndexReader reader, String field, ByteParser parser)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    /** @deprecated */
+    public Comparable[] getCustom(IndexReader reader, String field,
+        SortComparator comparator) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public float[] getFloats(IndexReader reader, String field)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public float[] getFloats(IndexReader reader, String field,
+        FloatParser parser) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public int[] getInts(IndexReader reader, String field) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public int[] getInts(IndexReader reader, String field, IntParser parser)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public short[] getShorts(IndexReader reader, String field)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public short[] getShorts(IndexReader reader, String field,
+        ShortParser parser) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public StringIndex getStringIndex(IndexReader reader, String field)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public String[] getStrings(IndexReader reader, String field)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+
+  static final class JustCompileExtendedFieldCacheLongParser implements ExtendedFieldCache.LongParser {
+
+    public long parseLong(String string) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+  
+  static final class JustCompileExtendedFieldCacheDoubleParser implements ExtendedFieldCache.DoubleParser {
+    
+    public double parseDouble(String string) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+
+  static final class JustCompileFieldComparator extends FieldComparator {
+
+    public int compare(int slot1, int slot2) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public int compareBottom(int doc) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public void copy(int slot, int doc) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public void setBottom(int slot) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public void setNextReader(IndexReader reader, int docBase, int numSlotsFull)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public int sortType() {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public Comparable value(int slot) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+
+  static final class JustCompileFieldComparatorSource extends FieldComparatorSource {
+
+    public FieldComparator newComparator(String fieldname, int numHits,
+        int sortPos, boolean reversed) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+
+  static final class JustCompileFilter extends Filter {
+    // Filter is just an abstract class with no abstract methods. However it is
+    // still added here in case someone will add abstract methods in the future.
+  }
+
+  static final class JustCompileFilteredDocIdSet extends FilteredDocIdSet {
+
+    public JustCompileFilteredDocIdSet(DocIdSet innerSet) {
+      super(innerSet);
+    }
+
+    protected boolean match(int docid) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+
+  static final class JustCompileFilteredDocIdSetIterator extends FilteredDocIdSetIterator {
+
+    public JustCompileFilteredDocIdSetIterator(DocIdSetIterator innerIter) {
+      super(innerIter);
+    }
+
+    protected boolean match(int doc) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+
+  static final class JustCompileFilteredTermEnum extends FilteredTermEnum {
+
+    public float difference() {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    protected boolean endEnum() {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    protected boolean termCompare(Term term) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+
+  static final class JustCompileMultiTermQuery extends MultiTermQuery {
+
+    protected FilteredTermEnum getEnum(IndexReader reader) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+
+  static final class JustCompilePhraseScorer extends PhraseScorer {
+
+    JustCompilePhraseScorer(Weight weight, TermPositions[] tps, int[] offsets,
+        Similarity similarity, byte[] norms) {
+      super(weight, tps, offsets, similarity, norms);
+    }
+
+    protected float phraseFreq() throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+
+  static final class JustCompileQuery extends Query {
+
+    public String toString(String field) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+  
+  static final class JustCompileScorer extends Scorer {
+
+    protected JustCompileScorer(Similarity similarity) {
+      super(similarity);
+    }
+
+    public Explanation explain(int doc) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public float score() throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public int doc() {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public boolean next() throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public boolean skipTo(int target) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+  
+  static final class JustCompileSimilarity extends Similarity {
+
+    public float coord(int overlap, int maxOverlap) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public float idf(int docFreq, int numDocs) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public float lengthNorm(String fieldName, int numTokens) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public float queryNorm(float sumOfSquaredWeights) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public float sloppyFreq(int distance) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public float tf(float freq) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+
+  static final class JustCompileSpanFilter extends SpanFilter {
+
+    public SpanFilterResult bitSpans(IndexReader reader) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+
+  static final class JustCompileTopDocsCollector extends TopDocsCollector {
+
+    protected JustCompileTopDocsCollector(PriorityQueue pq) {
+      super(pq);
+    }
+
+    public void collect(int doc) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public void setNextReader(IndexReader reader, int docBase)
+        throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public void setScorer(Scorer scorer) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+
+  static final class JustCompileWeight implements Weight {
+
+    public Explanation explain(IndexReader reader, int doc) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public Query getQuery() {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public float getValue() {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public void normalize(float norm) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public Scorer scorer(IndexReader reader) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public float sumOfSquaredWeights() throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+  
+}

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/QueryUtils.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/QueryUtils.java?rev=764551&r1=764550&r2=764551&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/QueryUtils.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/QueryUtils.java Mon Apr 13 18:33:56 2009
@@ -153,10 +153,15 @@
 
       final int[] sdoc = new int[] {-1};
       final float maxDiff = 1e-5f;
-      s.search(q,new MultiReaderHitCollector() {
-        private int base = -1;
-        public void collect(int doc, float score) {
+      s.search(q,new Collector() {
+        private int base = 0;
+        private Scorer sc;
+        public void setScorer(Scorer scorer) throws IOException {
+          this.sc = scorer;
+        }
+        public void collect(int doc) throws IOException {
           doc = doc + base;
+          float score = sc.score();
           try {
             int op = order[(opidx[0]++)%order.length];
             //System.out.println(op==skip_op ? "skip("+(sdoc[0]+1)+")":"next()");
@@ -205,11 +210,16 @@
     //System.out.println("checkFirstSkipTo: "+q);
     final float maxDiff = 1e-5f;
     final int lastDoc[] = {-1};
-    s.search(q,new MultiReaderHitCollector() {
-      private int base = -1;
-      public void collect(int doc, float score) {
+    s.search(q,new Collector() {
+      private int base = 0;
+      private Scorer scorer;
+      public void setScorer(Scorer scorer) throws IOException {
+        this.scorer = scorer;
+      }
+      public void collect(int doc) throws IOException {
         //System.out.println("doc="+doc);
         doc = doc + base;
+        float score = scorer.score();
         try {
           for (int i=lastDoc[0]+1; i<=doc; i++) {
             Weight w = q.weight(s);

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestDocBoost.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestDocBoost.java?rev=764551&r1=764550&r2=764551&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestDocBoost.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestDocBoost.java Mon Apr 13 18:33:56 2009
@@ -17,6 +17,8 @@
  * limitations under the License.
  */
 
+import java.io.IOException;
+
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.analysis.SimpleAnalyzer;
 import org.apache.lucene.document.*;
@@ -66,10 +68,14 @@
 
     new IndexSearcher(store).search
       (new TermQuery(new Term("field", "word")),
-       new MultiReaderHitCollector() {
-         private int base = -1;
-         public final void collect(int doc, float score) {
-           scores[doc + base] = score;
+       new Collector() {
+         private int base = 0;
+         private Scorer scorer;
+         public void setScorer(Scorer scorer) throws IOException {
+          this.scorer = scorer;
+         }
+         public final void collect(int doc) throws IOException {
+           scores[doc + base] = scorer.score();
          }
          public void setNextReader(IndexReader reader, int docBase) {
            base = docBase;

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java?rev=764551&r1=764550&r2=764551&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java Mon Apr 13 18:33:56 2009
@@ -168,10 +168,14 @@
     // must use a non score normalizing method for this.
     Query q = csrq("data", "1", "6", T, T);
     q.setBoost(100);
-    search.search(q, null, new MultiReaderHitCollector() {
-      private int base = -1;
-      public void collect(int doc, float score) {
-        assertEquals("score for doc " + (doc + base) + " was not correct", 1.0f, score);
+    search.search(q, null, new Collector() {
+      private int base = 0;
+      private Scorer scorer;
+      public void setScorer(Scorer scorer) throws IOException {
+        this.scorer = scorer;
+      }
+      public void collect(int doc) throws IOException {
+        assertEquals("score for doc " + (doc + base) + " was not correct", 1.0f, scorer.score());
       }
       public void setNextReader(IndexReader reader, int docBase) {
         base = docBase;

Added: lucene/java/trunk/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java?rev=764551&view=auto
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java (added)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java Mon Apr 13 18:33:56 2009
@@ -0,0 +1,85 @@
+package org.apache.lucene.search;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+
+import org.apache.lucene.util.LuceneTestCase;
+
+public class TestPositiveScoresOnlyCollector extends LuceneTestCase {
+
+  private static final class SimpleScorer extends Scorer {
+    private int idx = -1;
+    
+    public SimpleScorer() {
+      super(null);
+    }
+    
+    public Explanation explain(int doc) throws IOException { return null; }
+
+    public float score() throws IOException {
+      return idx == scores.length ? Float.NaN : scores[idx];
+    }
+
+    public int doc() { return idx; }
+
+    public boolean next() throws IOException { 
+      return ++idx == scores.length;
+    }
+
+    public boolean skipTo(int target) throws IOException {
+      idx = target;
+      return idx >= scores.length;
+    }
+  }
+
+  // The scores must have positive as well as negative values
+  private static final float[] scores = new float[] { 0.7767749f, -1.7839992f,
+      8.9925785f, 7.9608946f, -0.07948637f, 2.6356435f, 7.4950366f, 7.1490803f,
+      -8.108544f, 4.961808f, 2.2423935f, -7.285586f, 4.6699767f };
+
+  public void testNegativeScores() throws Exception {
+  
+    // The Top*Collectors previously filtered out documents with <= scores. This
+    // behavior has changed. This test checks that if PositiveOnlyScoresFilter
+    // wraps one of these collectors, documents with <= 0 scores are indeed
+    // filtered.
+    
+    int numPositiveScores = 0;
+    for (int i = 0; i < scores.length; i++) {
+      if (scores[i] > 0) {
+        ++numPositiveScores;
+      }
+    }
+    
+    Scorer s = new SimpleScorer();
+    TopDocsCollector tdc = new TopScoreDocCollector(scores.length);
+    Collector c = new PositiveScoresOnlyCollector(tdc);
+    c.setScorer(s);
+    while (!s.next()) {
+      c.collect(0);
+    }
+    TopDocs td = tdc.topDocs();
+    ScoreDoc[] sd = td.scoreDocs;
+    assertEquals(numPositiveScores, td.totalHits);
+    for (int i = 0; i < sd.length; i++) {
+      assertTrue("only positive scores should return: " + sd[i].score, sd[i].score > 0);
+    }
+  }
+  
+}

Added: lucene/java/trunk/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java?rev=764551&view=auto
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java (added)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java Mon Apr 13 18:33:56 2009
@@ -0,0 +1,111 @@
+package org.apache.lucene.search;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.util.LuceneTestCase;
+
+public class TestScoreCachingWrappingScorer extends LuceneTestCase {
+
+  private static final class SimpleScorer extends Scorer {
+    private int idx = 0;
+    private int doc = -1;
+    
+    public SimpleScorer() {
+      super(null);
+    }
+    
+    public Explanation explain(int doc) throws IOException { return null; }
+
+    public float score() throws IOException {
+      // advance idx on purpose, so that consecutive calls to score will get
+      // different results. This is to emulate computation of a score. If
+      // ScoreCachingWrappingScorer is used, this should not be called more than
+      // once per document.
+      return idx == scores.length ? Float.NaN : scores[idx++];
+    }
+
+    public int doc() { return doc; }
+
+    public boolean next() throws IOException { 
+      return ++doc == scores.length;
+    }
+
+    public boolean skipTo(int target) throws IOException {
+      doc = target;
+      return doc >= scores.length;
+    }
+  }
+  
+  private static final class ScoreCachingCollector extends Collector {
+
+    private int idx = 0;
+    private Scorer scorer;
+    float[] mscores;
+    
+    public ScoreCachingCollector(int numToCollect) {
+      mscores = new float[numToCollect];
+    }
+    
+    public void collect(int doc) throws IOException {
+      // just a sanity check to avoid IOOB.
+      if (idx == mscores.length) {
+        return; 
+      }
+      
+      // just call score() a couple of times and record the score.
+      mscores[idx] = scorer.score();
+      mscores[idx] = scorer.score();
+      mscores[idx] = scorer.score();
+      ++idx;
+    }
+
+    public void setNextReader(IndexReader reader, int docBase)
+        throws IOException {
+    }
+
+    public void setScorer(Scorer scorer) throws IOException {
+      this.scorer = new ScoreCachingWrappingScorer(scorer);
+    }
+    
+  }
+
+  private static final float[] scores = new float[] { 0.7767749f, 1.7839992f,
+      8.9925785f, 7.9608946f, 0.07948637f, 2.6356435f, 7.4950366f, 7.1490803f,
+      8.108544f, 4.961808f, 2.2423935f, 7.285586f, 4.6699767f };
+  
+  public void testGetScores() throws Exception {
+    
+    Scorer s = new SimpleScorer();
+    ScoreCachingCollector scc = new ScoreCachingCollector(scores.length);
+    scc.setScorer(s);
+    
+    // We need to iterate on the scorer so that its doc() advances.
+    while (!s.next()) {
+      scc.collect(s.doc());
+    }
+    
+    for (int i = 0; i < scores.length; i++) {
+      assertEquals(scores[i], scc.mscores[i], 0f);
+    }
+    
+  }
+  
+}

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestScorerPerf.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestScorerPerf.java?rev=764551&r1=764550&r2=764551&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestScorerPerf.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestScorerPerf.java Mon Apr 13 18:33:56 2009
@@ -96,14 +96,16 @@
     return sets;
   }
 
-  public static class CountingHitCollector extends MultiReaderHitCollector {
+  public static class CountingHitCollector extends Collector {
     int count=0;
     int sum=0;
-    protected int docBase = -1;
+    protected int docBase = 0;
 
-    public void collect(int doc, float score) {
+    public void setScorer(Scorer scorer) throws IOException {}
+    
+    public void collect(int doc) {
       count++;
-      sum += docBase+doc;  // use it to avoid any possibility of being optimized away
+      sum += docBase + doc;  // use it to avoid any possibility of being optimized away
     }
 
     public int getCount() { return count; }
@@ -123,11 +125,12 @@
     }
 
     public void collect(int doc, float score) {
+      
       pos = answer.nextSetBit(pos+1);
       if (pos != doc + docBase) {
         throw new RuntimeException("Expected doc " + pos + " but got " + doc + docBase);
       }
-      super.collect(doc,score);
+      super.collect(doc);
     }
   }
 

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestSetNorm.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestSetNorm.java?rev=764551&r1=764550&r2=764551&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestSetNorm.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestSetNorm.java Mon Apr 13 18:33:56 2009
@@ -17,6 +17,8 @@
  * limitations under the License.
  */
 
+import java.io.IOException;
+
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.analysis.SimpleAnalyzer;
 import org.apache.lucene.document.*;
@@ -62,10 +64,14 @@
 
     new IndexSearcher(store).search
       (new TermQuery(new Term("field", "word")),
-       new MultiReaderHitCollector() {
-         private int base = -1;
-         public final void collect(int doc, float score) {
-           scores[doc + base] = score;
+       new Collector() {
+         private int base = 0;
+         private Scorer scorer;
+         public void setScorer(Scorer scorer) throws IOException {
+          this.scorer = scorer;
+         }
+         public final void collect(int doc) throws IOException {
+           scores[doc + base] = scorer.score();
          }
          public void setNextReader(IndexReader reader, int docBase) {
            base = docBase;

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestSimilarity.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestSimilarity.java?rev=764551&r1=764550&r2=764551&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestSimilarity.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestSimilarity.java Mon Apr 13 18:33:56 2009
@@ -19,6 +19,7 @@
 
 import org.apache.lucene.util.LuceneTestCase;
 
+import java.io.IOException;
 import java.util.Collection;
 
 import org.apache.lucene.index.IndexReader;
@@ -75,9 +76,13 @@
 
     searcher.search
       (new TermQuery(b),
-       new MultiReaderHitCollector() {
-         public final void collect(int doc, float score) {
-           assertTrue(score == 1.0f);
+       new Collector() {
+         private Scorer scorer;
+         public void setScorer(Scorer scorer) throws IOException {
+           this.scorer = scorer; 
+         }
+         public final void collect(int doc) throws IOException {
+           assertTrue(scorer.score() == 1.0f);
          }
          public void setNextReader(IndexReader reader, int docBase) {}
        });
@@ -88,11 +93,15 @@
     //System.out.println(bq.toString("field"));
     searcher.search
       (bq,
-       new MultiReaderHitCollector() {
-         private int base = -1;
-         public final void collect(int doc, float score) {
+       new Collector() {
+         private int base = 0;
+         private Scorer scorer;
+         public void setScorer(Scorer scorer) throws IOException {
+           this.scorer = scorer; 
+         }
+         public final void collect(int doc) throws IOException {
            //System.out.println("Doc=" + doc + " score=" + score);
-           assertTrue(score == (float)doc+base+1);
+           assertTrue(scorer.score() == (float)doc+base+1);
          }
          public void setNextReader(IndexReader reader, int docBase) {
            base = docBase;
@@ -105,10 +114,14 @@
     //System.out.println(pq.toString("field"));
     searcher.search
       (pq,
-       new MultiReaderHitCollector() {
-         public final void collect(int doc, float score) {
+       new Collector() {
+        private Scorer scorer;
+        public void setScorer(Scorer scorer) throws IOException {
+          this.scorer = scorer; 
+        }
+         public final void collect(int doc) throws IOException {
            //System.out.println("Doc=" + doc + " score=" + score);
-           assertTrue(score == 1.0f);
+           assertTrue(scorer.score() == 1.0f);
          }
          public void setNextReader(IndexReader reader, int docBase) {}
        });
@@ -117,10 +130,14 @@
     //System.out.println(pq.toString("field"));
     searcher.search
       (pq,
-       new MultiReaderHitCollector() {
-         public final void collect(int doc, float score) {
+       new Collector() {
+        private Scorer scorer;
+        public void setScorer(Scorer scorer) throws IOException {
+          this.scorer = scorer; 
+        }
+         public final void collect(int doc) throws IOException {
            //System.out.println("Doc=" + doc + " score=" + score);
-           assertTrue(score == 2.0f);
+           assertTrue(scorer.score() == 2.0f);
          }
          public void setNextReader(IndexReader reader, int docBase) {}
        });

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java?rev=764551&r1=764550&r2=764551&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java Mon Apr 13 18:33:56 2009
@@ -413,7 +413,7 @@
       slotValues = new int[numHits];
     }
 
-    public void copy(int slot, int doc, float score) {
+    public void copy(int slot, int doc) {
       slotValues[slot] = docValues[doc];
     }
 
@@ -421,7 +421,7 @@
       return slotValues[slot1] - slotValues[slot2];
     }
 
-    public int compareBottom(int doc, float score) {
+    public int compareBottom(int doc) {
       return bottomValue - docValues[doc];
     }
 
@@ -447,7 +447,7 @@
   }
 
   static class MyFieldComparatorSource extends FieldComparatorSource {
-    public FieldComparator newComparator(String fieldname, IndexReader[] subReaders, int numHits, int sortPos, boolean reversed) {
+    public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) {
       return new MyFieldComparator(numHits);
     }
   }
@@ -803,7 +803,94 @@
     
     assertEquals(docs1.scoreDocs[0].score, docs2.scoreDocs[0].score, 1e-6);
   }
+  
+  public void testSortWithoutFillFields() throws Exception {
+    
+    // There was previously a bug in TopFieldCollector when fillFields was set
+    // to false - the same doc and score was set in ScoreDoc[] array. This test
+    // asserts that if fillFields is false, the documents are set properly. It
+    // does not use Searcher's default search methods (with Sort) since all set
+    // fillFields to true.
+    Sort[] sort = new Sort[] { new Sort(SortField.FIELD_DOC), new Sort() };
+    for (int i = 0; i < sort.length; i++) {
+      TopDocsCollector tdc = TopFieldCollector.create(sort[i], 10, false, false, false);
+      
+      full.search(new MatchAllDocsQuery(), tdc);
+      
+      ScoreDoc[] sd = tdc.topDocs().scoreDocs;
+      for (int j = 1; j < sd.length; j++) {
+        assertTrue(sd[j].doc != sd[j - 1].doc);
+      }
+      
+    }
+  }
+
+  public void testSortWithoutScoreTracking() throws Exception {
 
+    // Two Sort criteria to instantiate the multi/single comparators.
+    Sort[] sort = new Sort[] {new Sort(SortField.FIELD_DOC), new Sort() };
+    for (int i = 0; i < sort.length; i++) {
+      TopDocsCollector tdc = TopFieldCollector.create(sort[i], 10, true, false, false);
+      
+      full.search(new MatchAllDocsQuery(), tdc);
+      
+      TopDocs td = tdc.topDocs();
+      ScoreDoc[] sd = td.scoreDocs;
+      for (int j = 0; j < sd.length; j++) {
+        assertTrue(Float.isNaN(sd[j].score));
+      }
+      assertTrue(Float.isNaN(td.getMaxScore()));
+    }
+  }
+  
+  public void testSortWithScoreNoMaxScoreTracking() throws Exception {
+    
+    // Two Sort criteria to instantiate the multi/single comparators.
+    Sort[] sort = new Sort[] {new Sort(SortField.FIELD_DOC), new Sort() };
+    for (int i = 0; i < sort.length; i++) {
+      TopDocsCollector tdc = TopFieldCollector.create(sort[i], 10, true, true, false);
+      
+      full.search(new MatchAllDocsQuery(), tdc);
+      
+      TopDocs td = tdc.topDocs();
+      ScoreDoc[] sd = td.scoreDocs;
+      for (int j = 0; j < sd.length; j++) {
+        assertTrue(!Float.isNaN(sd[j].score));
+      }
+      assertTrue(Float.isNaN(td.getMaxScore()));
+    }
+  }
+  
+  public void testSortWithScoreAndMaxScoreTracking() throws Exception {
+    
+    // Two Sort criteria to instantiate the multi/single comparators.
+    Sort[] sort = new Sort[] {new Sort(SortField.FIELD_DOC), new Sort() };
+    for (int i = 0; i < sort.length; i++) {
+      TopDocsCollector tdc = TopFieldCollector.create(sort[i], 10, true, true, true);
+      
+      full.search(new MatchAllDocsQuery(), tdc);
+      
+      TopDocs td = tdc.topDocs();
+      ScoreDoc[] sd = td.scoreDocs;
+      for (int j = 0; j < sd.length; j++) {
+        assertTrue(!Float.isNaN(sd[j].score));
+      }
+      assertTrue(!Float.isNaN(td.getMaxScore()));
+    }
+  }
+  
+  public void testSortWithScoreAndMaxScoreTrackingNoResults() throws Exception {
+    
+    // Two Sort criteria to instantiate the multi/single comparators.
+    Sort[] sort = new Sort[] {new Sort(SortField.FIELD_DOC), new Sort() };
+    for (int i = 0; i < sort.length; i++) {
+      TopDocsCollector tdc = TopFieldCollector.create(sort[i], 10, true, true, true);
+      TopDocs td = tdc.topDocs();
+      assertEquals(0, td.totalHits);
+      assertTrue(Float.isNaN(td.getMaxScore()));
+    }
+  }
+  
   // runs a variety of sorts useful for multisearchers
   private void runMultiSorts (Searcher multi) throws Exception {
     sort.setSort (SortField.FIELD_DOC);

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestTermScorer.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestTermScorer.java?rev=764551&r1=764550&r2=764551&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestTermScorer.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestTermScorer.java Mon Apr 13 18:33:56 2009
@@ -65,8 +65,7 @@
 
     }
 
-    public void test() throws IOException
-    {
+    public void test() throws IOException {
 
         Term allTerm = new Term(FIELD, "all");
         TermQuery termQuery = new TermQuery(allTerm);
@@ -76,21 +75,25 @@
         TermScorer ts = new TermScorer(weight,
                                        indexReader.termDocs(allTerm), indexSearcher.getSimilarity(),
                                        indexReader.norms(FIELD));
-        assertTrue("ts is null and it shouldn't be", ts != null);
         //we have 2 documents with the term all in them, one document for all the other values
         final List docs = new ArrayList();
         //must call next first
 
 
-        ts.score(new MultiReaderHitCollector()
-        {
-            private int base = -1;
-            public void collect(int doc, float score)
-            {
-                docs.add(new TestHit(doc + base, score));
-                assertTrue("score " + score + " is not greater than 0", score > 0);
-                assertTrue("Doc: " + doc + " does not equal: " + 0 +
-                        " or doc does not equaal: " + 5, doc == 0 || doc == 5);
+        ts.score(new Collector() {
+            private int base = 0;
+            private Scorer scorer;
+            public void setScorer(Scorer scorer) throws IOException {
+              this.scorer = scorer; 
+            }
+
+            public void collect(int doc) throws IOException {
+              float score = scorer.score();
+              doc = doc + base;
+              docs.add(new TestHit(doc, score));
+              assertTrue("score " + score + " is not greater than 0", score > 0);
+              assertTrue("Doc: " + doc + " does not equal 0 or doc does not equal 5",
+                            doc == 0 || doc == 5);
             }
             public void setNextReader(IndexReader reader, int docBase) {
               base = docBase;
@@ -121,8 +124,7 @@
         assertTrue(doc0.score + " does not equal: " + 1.6931472f, doc0.score == 1.6931472f);
     }
 
-    public void testNext() throws Exception
-    {
+    public void testNext() throws Exception {
 
         Term allTerm = new Term(FIELD, "all");
         TermQuery termQuery = new TermQuery(allTerm);
@@ -132,7 +134,6 @@
         TermScorer ts = new TermScorer(weight,
                                        indexReader.termDocs(allTerm), indexSearcher.getSimilarity(),
                                        indexReader.norms(FIELD));
-        assertTrue("ts is null and it shouldn't be", ts != null);
         assertTrue("next did not return a doc", ts.next() == true);
         assertTrue("score is not correct", ts.score() == 1.6931472f);
         assertTrue("next did not return a doc", ts.next() == true);
@@ -140,8 +141,7 @@
         assertTrue("next returned a doc and it should not have", ts.next() == false);
     }
 
-    public void testSkipTo() throws Exception
-    {
+    public void testSkipTo() throws Exception {
 
         Term allTerm = new Term(FIELD, "all");
         TermQuery termQuery = new TermQuery(allTerm);
@@ -151,7 +151,6 @@
         TermScorer ts = new TermScorer(weight,
                                        indexReader.termDocs(allTerm), indexSearcher.getSimilarity(),
                                        indexReader.norms(FIELD));
-        assertTrue("ts is null and it shouldn't be", ts != null);
         assertTrue("Didn't skip", ts.skipTo(3) == true);
         //The next doc should be doc 5
         assertTrue("doc should be number 5", ts.doc() == 5);
@@ -167,7 +166,6 @@
         TermScorer ts = new TermScorer(weight,
                                        indexReader.termDocs(allTerm), indexSearcher.getSimilarity(),
                                        indexReader.norms(FIELD));
-        assertTrue("ts is null and it shouldn't be", ts != null);
         Explanation explanation = ts.explain(0);
         assertTrue("explanation is null and it shouldn't be", explanation != null);
         //System.out.println("Explanation: " + explanation.toString());
@@ -185,7 +183,6 @@
 
         ts = new TermScorer(weight, indexReader.termDocs(dogsTerm), indexSearcher.getSimilarity(),
                                        indexReader.norms(FIELD));
-        assertTrue("ts is null and it shouldn't be", ts != null);
         explanation = ts.explain(1);
         assertTrue("explanation is null and it shouldn't be", explanation != null);
         //System.out.println("Explanation: " + explanation.toString());
@@ -202,23 +199,17 @@
 
     }
 
-    private class TestHit
-    {
+    private class TestHit {
         public int doc;
         public float score;
 
-        public TestHit(int doc, float score)
-        {
+        public TestHit(int doc, float score) {
             this.doc = doc;
             this.score = score;
         }
 
-        public String toString()
-        {
-            return "TestHit{" +
-                    "doc=" + doc +
-                    ", score=" + score +
-                    "}";
+        public String toString() {
+            return "TestHit{" + "doc=" + doc + ", score=" + score + "}";
         }
     }
 

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestTimeLimitedCollector.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestTimeLimitedCollector.java?rev=764551&r1=764550&r2=764551&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestTimeLimitedCollector.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestTimeLimitedCollector.java Mon Apr 13 18:33:56 2009
@@ -20,7 +20,6 @@
 import org.apache.lucene.analysis.WhitespaceAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
-import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.IndexWriter.MaxFieldLength;
 import org.apache.lucene.queryParser.QueryParser;
@@ -287,12 +286,11 @@
   }
   
   // counting hit collector that can slow down at collect().
-  private class MyHitCollector extends MultiReaderHitCollector
+  private class MyHitCollector extends HitCollector
   {
     private final BitSet bits = new BitSet();
     private int slowdown = 0;
     private int lastDocCollected = -1;
-    private int docBase = -1;
 
     /**
      * amount of time to wait on each collect to simulate a long iteration
@@ -301,8 +299,7 @@
       slowdown = milliseconds;
     }
     
-    public void collect( final int doc, final float score ) {
-      int docId = doc + docBase;
+    public void collect( final int docId, final float score ) {
       if( slowdown > 0 ) {
         try {
           Thread.sleep(slowdown);
@@ -311,7 +308,7 @@
           throw new RuntimeException(ie);
         }
       }
-      assert docId >= 0: " base=" + docBase + " doc=" + doc;
+      assert docId >= 0: " doc=" + docId;
       bits.set( docId );
       lastDocCollected = docId;
     }
@@ -323,11 +320,6 @@
     public int getLastDocCollected() {
       return lastDocCollected;
     }
-
-    public void setNextReader(IndexReader reader, int base) {
-      docBase = base;
-    }
-    
   }
 
 }

Added: lucene/java/trunk/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java?rev=764551&view=auto
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java (added)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java Mon Apr 13 18:33:56 2009
@@ -0,0 +1,337 @@
+package org.apache.lucene.search;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.util.BitSet;
+
+import org.apache.lucene.analysis.WhitespaceAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriter.MaxFieldLength;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.TimeLimitingCollector.TimeExceededException;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.util.LuceneTestCase;
+
+/**
+ * Tests the {@link TimeLimitingCollector}.  This test checks (1) search
+ * correctness (regardless of timeout), (2) expected timeout behavior,
+ * and (3) a sanity test with multiple searching threads.
+ */
+public class TestTimeLimitingCollector extends LuceneTestCase {
+  private static final int SLOW_DOWN = 47;
+  private static final long TIME_ALLOWED = 17 * SLOW_DOWN; // so searches can find about 17 docs.
+  
+  // max time allowed is relaxed for multithreading tests. 
+  // the multithread case fails when setting this to 1 (no slack) and launching many threads (>2000).  
+  // but this is not a real failure, just noise.
+  private static final double MULTI_THREAD_SLACK = 7;      
+            
+  private static final int N_DOCS = 3000;
+  private static final int N_THREADS = 50;
+
+  private Searcher searcher;
+  private final String FIELD_NAME = "body";
+  private Query query;
+
+  public TestTimeLimitingCollector(String name) {
+    super(name);
+  }
+
+  /**
+   * initializes searcher with a document set
+   */
+  protected void setUp() throws Exception {
+    final String docText[] = {
+        "docThatNeverMatchesSoWeCanRequireLastDocCollectedToBeGreaterThanZero",
+        "one blah three",
+        "one foo three multiOne",
+        "one foobar three multiThree",
+        "blueberry pancakes",
+        "blueberry pie",
+        "blueberry strudel",
+        "blueberry pizza",
+    };
+    Directory directory = new RAMDirectory();
+    IndexWriter iw = new IndexWriter(directory, new WhitespaceAnalyzer(), true, MaxFieldLength.UNLIMITED);
+    
+    for (int i=0; i<N_DOCS; i++) {
+      add(docText[i%docText.length], iw);
+    }
+    iw.close();
+    searcher = new IndexSearcher(directory);
+
+    String qtxt = "one";
+    for (int i = 0; i < docText.length; i++) {
+      qtxt += ' ' + docText[i]; // large query so that search will be longer
+    }
+    QueryParser queryParser = new QueryParser(FIELD_NAME, new WhitespaceAnalyzer());
+    query = queryParser.parse(qtxt);
+    
+    // warm the searcher
+    searcher.search(query, null, 1000);
+
+  }
+
+  public void tearDown() throws Exception {
+    searcher.close();
+  }
+
+  private void add(String value, IndexWriter iw) throws IOException {
+    Document d = new Document();
+    d.add(new Field(FIELD_NAME, value, Field.Store.NO, Field.Index.ANALYZED));
+    iw.addDocument(d);
+  }
+
+  private void search(Collector collector) throws Exception {
+    searcher.search(query, collector);
+  }
+
+  /**
+   * test search correctness with no timeout
+   */
+  public void testSearch() {
+    doTestSearch();
+  }
+  
+  private void doTestSearch() {
+    int totalResults = 0;
+    int totalTLCResults = 0;
+    try {
+      MyHitCollector myHc = new MyHitCollector();
+      search(myHc);
+      totalResults = myHc.hitCount();
+      
+      myHc = new MyHitCollector();
+      long oneHour = 3600000;
+      Collector tlCollector = createTimedCollector(myHc, oneHour, false);
+      search(tlCollector);
+      totalTLCResults = myHc.hitCount();
+    } catch (Exception e) {
+      e.printStackTrace();
+      assertTrue("Unexpected exception: "+e, false); //==fail
+    }
+    assertEquals( "Wrong number of results!", totalResults, totalTLCResults );
+  }
+
+  private Collector createTimedCollector(MyHitCollector hc, long timeAllowed, boolean greedy) {
+    TimeLimitingCollector res = new TimeLimitingCollector(hc, timeAllowed);
+    res.setGreedy(greedy); // set to true to make sure at least one doc is collected.
+    return res;
+  }
+
+  /**
+   * Test that timeout is obtained, and soon enough!
+   */
+  public void testTimeoutGreedy() {
+    doTestTimeout(false, true);
+  }
+  
+  /**
+   * Test that timeout is obtained, and soon enough!
+   */
+  public void testTimeoutNotGreedy() {
+    doTestTimeout(false, false);
+  }
+
+  private void doTestTimeout(boolean multiThreaded, boolean greedy) {
+    // setup
+    MyHitCollector myHc = new MyHitCollector();
+    myHc.setSlowDown(SLOW_DOWN);
+    Collector tlCollector = createTimedCollector(myHc, TIME_ALLOWED, greedy);
+
+    // search
+    TimeExceededException timoutException = null;
+    try {
+      search(tlCollector);
+    } catch (TimeExceededException x) {
+      timoutException = x;
+    } catch (Exception e) {
+      assertTrue("Unexpected exception: "+e, false); //==fail
+    }
+    
+    // must get exception
+    assertNotNull( "Timeout expected!", timoutException );
+
+    // greediness affect last doc collected
+    int exceptionDoc = timoutException.getLastDocCollected();
+    int lastCollected = myHc.getLastDocCollected(); 
+    assertTrue( "doc collected at timeout must be > 0!", exceptionDoc > 0 );
+    if (greedy) {
+      assertTrue("greedy="+greedy+" exceptionDoc="+exceptionDoc+" != lastCollected="+lastCollected, exceptionDoc==lastCollected);
+      assertTrue("greedy, but no hits found!", myHc.hitCount() > 0 );
+    } else {
+      assertTrue("greedy="+greedy+" exceptionDoc="+exceptionDoc+" not > lastCollected="+lastCollected, exceptionDoc>lastCollected);
+    }
+
+    // verify that elapsed time at exception is within valid limits
+    assertEquals( timoutException.getTimeAllowed(), TIME_ALLOWED);
+    // a) Not too early
+    assertTrue ( "elapsed="+timoutException.getTimeElapsed()+" <= (allowed-resolution)="+(TIME_ALLOWED-TimeLimitingCollector.getResolution()),
+        timoutException.getTimeElapsed() > TIME_ALLOWED-TimeLimitingCollector.getResolution());
+    // b) Not too late.
+    //    This part is problematic in a busy test system, so we just print a warning.
+    //    We already verified that a timeout occurred, we just can't be picky about how long it took.
+    if (timoutException.getTimeElapsed() > maxTime(multiThreaded)) {
+      System.out.println("Informative: timeout exceeded (no action required: most probably just " +
+        " because the test machine is slower than usual):  " +
+        "lastDoc="+exceptionDoc+
+        " ,&& allowed="+timoutException.getTimeAllowed() +
+        " ,&& elapsed="+timoutException.getTimeElapsed() +
+        " >= " + maxTimeStr(multiThreaded));
+    }
+  }
+
+  private long maxTime(boolean multiThreaded) {
+    long res = 2 * TimeLimitingCollector.getResolution() + TIME_ALLOWED + SLOW_DOWN; // some slack for less noise in this test
+    if (multiThreaded) {
+      res *= MULTI_THREAD_SLACK; // larger slack  
+    }
+    return res;
+  }
+
+  private String maxTimeStr(boolean multiThreaded) {
+    String s =
+      "( " +
+      "2*resolution +  TIME_ALLOWED + SLOW_DOWN = " +
+      "2*" + TimeLimitingCollector.getResolution() + " + " + TIME_ALLOWED + " + " + SLOW_DOWN +
+      ")";
+    if (multiThreaded) {
+      s = MULTI_THREAD_SLACK + " * "+s;  
+    }
+    return maxTime(multiThreaded) + " = " + s;
+  }
+
+  /**
+   * Test timeout behavior when resolution is modified. 
+   */
+  public void testModifyResolution() {
+    try {
+      // increase and test
+      long resolution = 20 * TimeLimitingCollector.DEFAULT_RESOLUTION; //400
+      TimeLimitingCollector.setResolution(resolution);
+      assertEquals(resolution, TimeLimitingCollector.getResolution());
+      doTestTimeout(false,true);
+      // decrease much and test
+      resolution = 5;
+      TimeLimitingCollector.setResolution(resolution);
+      assertEquals(resolution, TimeLimitingCollector.getResolution());
+      doTestTimeout(false,true);
+      // return to default and test
+      resolution = TimeLimitingCollector.DEFAULT_RESOLUTION;
+      TimeLimitingCollector.setResolution(resolution);
+      assertEquals(resolution, TimeLimitingCollector.getResolution());
+      doTestTimeout(false,true);
+    } finally {
+      TimeLimitingCollector.setResolution(TimeLimitingCollector.DEFAULT_RESOLUTION);
+    }
+  }
+  
+  /** 
+   * Test correctness with multiple searching threads.
+   */
+  public void testSearchMultiThreaded() throws Exception {
+    doTestMultiThreads(false);
+  }
+
+  /** 
+   * Test correctness with multiple searching threads.
+   */
+  public void testTimeoutMultiThreaded() throws Exception {
+    doTestMultiThreads(true);
+  }
+  
+  private void doTestMultiThreads(final boolean withTimeout) throws Exception {
+    Thread [] threadArray = new Thread[N_THREADS];
+    final BitSet success = new BitSet(N_THREADS);
+    for( int i = 0; i < threadArray.length; ++i ) {
+      final int num = i;
+      threadArray[num] = new Thread() {
+          public void run() {
+            if (withTimeout) {
+              doTestTimeout(true,true);
+            } else {
+              doTestSearch();
+            }
+            synchronized(success) {
+              success.set(num);
+            }
+          }
+      };
+    }
+    for( int i = 0; i < threadArray.length; ++i ) {
+      threadArray[i].start();
+    }
+    for( int i = 0; i < threadArray.length; ++i ) {
+      threadArray[i].join();
+    }
+    assertEquals("some threads failed!", N_THREADS,success.cardinality());
+  }
+  
+  // counting collector that can slow down at collect().
+  private class MyHitCollector extends Collector {
+    private final BitSet bits = new BitSet();
+    private int slowdown = 0;
+    private int lastDocCollected = -1;
+    private int docBase = 0;
+
+    /**
+     * amount of time to wait on each collect to simulate a long iteration
+     */
+    public void setSlowDown( int milliseconds ) {
+      slowdown = milliseconds;
+    }
+    
+    public int hitCount() {
+      return bits.cardinality();
+    }
+
+    public int getLastDocCollected() {
+      return lastDocCollected;
+    }
+
+    public void setScorer(Scorer scorer) throws IOException {
+      // scorer is not needed
+    }
+    
+    public void collect(final int doc) throws IOException {
+      int docId = doc + docBase;
+      if( slowdown > 0 ) {
+        try {
+          Thread.sleep(slowdown);
+        } catch (InterruptedException ie) {
+          Thread.currentThread().interrupt();
+          throw new RuntimeException(ie);
+        }
+      }
+      assert docId >= 0: " base=" + docBase + " doc=" + doc;
+      bits.set( docId );
+      lastDocCollected = docId;
+    }
+    
+    public void setNextReader(IndexReader reader, int base) {
+      docBase = base;
+    }
+    
+  }
+
+}

Added: lucene/java/trunk/src/test/org/apache/lucene/search/TestTopDocsCollector.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestTopDocsCollector.java?rev=764551&view=auto
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestTopDocsCollector.java (added)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestTopDocsCollector.java Mon Apr 13 18:33:56 2009
@@ -0,0 +1,198 @@
+package org.apache.lucene.search;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+
+import org.apache.lucene.analysis.KeywordAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriter.MaxFieldLength;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.util.LuceneTestCase;
+
+public class TestTopDocsCollector extends LuceneTestCase {
+
+  private static final class MyTopsDocCollector extends TopDocsCollector {
+
+    private int idx = 0;
+    private int base = 0;
+    
+    public MyTopsDocCollector(int size) {
+      super(new HitQueue(size));
+    }
+    
+    protected TopDocs newTopDocs(ScoreDoc[] results, int start) {
+      if (results == null) {
+        return EMPTY_TOPDOCS;
+      }
+      
+      float maxScore = Float.NaN;
+      if (start == 0) {
+        maxScore = results[0].score;
+      } else {
+        for (int i = pq.size(); i > 1; i--) { pq.pop(); }
+        maxScore = ((ScoreDoc) pq.pop()).score;
+      }
+      
+      return new TopDocs(totalHits, results, maxScore);
+    }
+    
+    public void collect(int doc) throws IOException {
+      pq.insert(new ScoreDoc(doc + base, scores[idx++]));
+    }
+
+    public void setNextReader(IndexReader reader, int docBase)
+        throws IOException {
+      base = docBase;
+    }
+
+    public void setScorer(Scorer scorer) throws IOException {
+      // Don't do anything. Assign scores in random
+    }
+    
+  }
+
+  // Scores array to be used by MyTopDocsCollector. If it is changed, MAX_SCORE
+  // must also change.
+  private static final float[] scores = new float[] {
+    0.7767749f, 1.7839992f, 8.9925785f, 7.9608946f, 0.07948637f, 2.6356435f, 
+    7.4950366f, 7.1490803f, 8.108544f, 4.961808f, 2.2423935f, 7.285586f, 4.6699767f,
+    2.9655676f, 6.953706f, 5.383931f, 6.9916306f, 8.365894f, 7.888485f, 8.723962f,
+    3.1796896f, 0.39971232f, 1.3077754f, 6.8489285f, 9.17561f, 5.060466f, 7.9793315f,
+    8.601509f, 4.1858315f, 0.28146625f
+  };
+  
+  private static final float MAX_SCORE = 9.17561f;
+  
+  private Directory dir = new RAMDirectory();
+
+  private TopDocsCollector doSearch(int numResults) throws IOException {
+    Query q = new MatchAllDocsQuery();
+    IndexSearcher searcher = new IndexSearcher(dir);
+    TopDocsCollector tdc = new MyTopsDocCollector(numResults);
+    searcher.search(q, tdc);
+    searcher.close();
+    return tdc;
+  }
+  
+  protected void setUp() throws Exception {
+    super.setUp();
+    
+    // populate an index with 30 documents, this should be enough for the test.
+    // The documents have no content - the test uses MatchAllDocsQuery().
+    IndexWriter writer = new IndexWriter(dir, new KeywordAnalyzer(), MaxFieldLength.UNLIMITED);
+    for (int i = 0; i < 30; i++) {
+      writer.addDocument(new Document());
+    }
+    writer.close();
+  }
+  
+  protected void tearDown() throws Exception {
+    dir.close();
+    dir = null;
+    super.tearDown();
+  }
+  
+  public void testInvalidArguments() throws Exception {
+    int numResults = 5;
+    TopDocsCollector tdc = doSearch(numResults);
+    
+    // start < 0
+    assertEquals(0, tdc.topDocs(-1).scoreDocs.length);
+    
+    // start > pq.size()
+    assertEquals(0, tdc.topDocs(numResults + 1).scoreDocs.length);
+    
+    // start == pq.size()
+    assertEquals(0, tdc.topDocs(numResults).scoreDocs.length);
+    
+    // howMany < 0
+    assertEquals(0, tdc.topDocs(0, -1).scoreDocs.length);
+    
+    // howMany == 0
+    assertEquals(0, tdc.topDocs(0, 0).scoreDocs.length);
+    
+  }
+  
+  public void testZeroResults() throws Exception {
+    TopDocsCollector tdc = new MyTopsDocCollector(5);
+    assertEquals(0, tdc.topDocs(0, 1).scoreDocs.length);
+  }
+  
+  public void testFirstResultsPage() throws Exception {
+    TopDocsCollector tdc = doSearch(15);
+    assertEquals(10, tdc.topDocs(0, 10).scoreDocs.length);
+  }
+  
+  public void testSecondResultsPages() throws Exception {
+    TopDocsCollector tdc = doSearch(15);
+    // ask for more results than are available
+    assertEquals(5, tdc.topDocs(10, 10).scoreDocs.length);
+    
+    // ask for 5 results (exactly what there should be
+    tdc = doSearch(15);
+    assertEquals(5, tdc.topDocs(10, 5).scoreDocs.length);
+    
+    // ask for less results than there are
+    tdc = doSearch(15);
+    assertEquals(4, tdc.topDocs(10, 4).scoreDocs.length);
+  }
+  
+  public void testGetAllResults() throws Exception {
+    TopDocsCollector tdc = doSearch(15);
+    assertEquals(15, tdc.topDocs().scoreDocs.length);
+  }
+  
+  public void testGetResultsFromStart() throws Exception {
+    TopDocsCollector tdc = doSearch(15);
+    // should bring all results
+    assertEquals(15, tdc.topDocs(0).scoreDocs.length);
+    
+    tdc = doSearch(15);
+    // get the last 5 only.
+    assertEquals(5, tdc.topDocs(10).scoreDocs.length);
+  }
+  
+  public void testMaxScore() throws Exception {
+    // ask for all results
+    TopDocsCollector tdc = doSearch(15);
+    TopDocs td = tdc.topDocs();
+    assertEquals(MAX_SCORE, td.getMaxScore(), 0f);
+    
+    // ask for 5 last results
+    tdc = doSearch(15);
+    td = tdc.topDocs(10);
+    assertEquals(MAX_SCORE, td.getMaxScore(), 0f);
+  }
+  
+  // This does not test the PQ's correctness, but whether topDocs()
+  // implementations return the results in decreasing score order.
+  public void testResultsOrder() throws Exception {
+    TopDocsCollector tdc = doSearch(15);
+    ScoreDoc[] sd = tdc.topDocs().scoreDocs;
+    
+    assertEquals(MAX_SCORE, sd[0].score, 0f);
+    for (int i = 1; i < sd.length; i++) {
+      assertTrue(sd[i - 1].score >= sd[i].score);
+    }
+  }
+  
+}

Added: lucene/java/trunk/src/test/org/apache/lucene/search/function/JustCompileSearchSpans.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/function/JustCompileSearchSpans.java?rev=764551&view=auto
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/function/JustCompileSearchSpans.java (added)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/function/JustCompileSearchSpans.java Mon Apr 13 18:33:56 2009
@@ -0,0 +1,89 @@
+package org.apache.lucene.search.function;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.FieldCache;
+
+/**
+ * Holds all implementations of classes in the o.a.l.s.function package as a
+ * back-compatibility test. It does not run any tests per-se, however if
+ * someone adds a method to an interface or abstract method to an abstract
+ * class, one of the implementations here will fail to compile and so we know
+ * back-compat policy was violated.
+ */
+final class JustCompileSearchFunction {
+
+  private static final String UNSUPPORTED_MSG = "unsupported: used for back-compat testing only !";
+
+  static final class JustCompileDocValues extends DocValues {
+
+    public float floatVal(int doc) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public String toString(int doc) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+
+  static final class JustCompileFieldCacheSource extends FieldCacheSource {
+
+    public JustCompileFieldCacheSource(String field) {
+      super(field);
+    }
+
+    public boolean cachedFieldSourceEquals(FieldCacheSource other) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public int cachedFieldSourceHashCode() {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public DocValues getCachedFieldValues(FieldCache cache, String field,
+        IndexReader reader) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+
+  static final class JustCompileValueSource extends ValueSource {
+
+    public String description() {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public boolean equals(Object o) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public DocValues getValues(IndexReader reader) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public int hashCode() {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+  
+}

Added: lucene/java/trunk/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java?rev=764551&view=auto
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java (added)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java Mon Apr 13 18:33:56 2009
@@ -0,0 +1,112 @@
+package org.apache.lucene.search.spans;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.util.Collection;
+
+import org.apache.lucene.index.IndexReader;
+
+/**
+ * Holds all implementations of classes in the o.a.l.s.spans package as a
+ * back-compatibility test. It does not run any tests per-se, however if
+ * someone adds a method to an interface or abstract method to an abstract
+ * class, one of the implementations here will fail to compile and so we know
+ * back-compat policy was violated.
+ */
+final class JustCompileSearchSpans {
+
+  private static final String UNSUPPORTED_MSG = "unsupported: used for back-compat testing only !";
+
+  static final class JustCompileSpans implements Spans {
+
+    public int doc() {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public int end() {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public boolean next() throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public boolean skipTo(int target) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public int start() {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+
+  static final class JustCompileSpanQuery extends SpanQuery {
+
+    public String getField() {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public Spans getSpans(IndexReader reader) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public Collection getTerms() {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public String toString(String field) {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+
+  static final class JustCompilePayloadSpans implements PayloadSpans {
+
+    public Collection getPayload() throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public boolean isPayloadAvailable() {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public int doc() {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public int end() {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public boolean next() throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public boolean skipTo(int target) throws IOException {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+
+    public int start() {
+      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+    }
+    
+  }
+  
+}



Mime
View raw message