lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r826857 - /lucene/java/trunk/src/java/org/apache/lucene/search/
Date Mon, 19 Oct 2009 22:59:07 GMT
Author: uschindler
Date: Mon Oct 19 22:59:06 2009
New Revision: 826857

URL: http://svn.apache.org/viewvc?rev=826857&view=rev
Log:
LUCENE-1257:LUCENE-1257: More generified APIs and implementations.

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/search/FieldCacheImpl.java
    lucene/java/trunk/src/java/org/apache/lucene/search/FieldValueHitQueue.java
    lucene/java/trunk/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java
    lucene/java/trunk/src/java/org/apache/lucene/search/NumericRangeFilter.java
    lucene/java/trunk/src/java/org/apache/lucene/search/PrefixFilter.java
    lucene/java/trunk/src/java/org/apache/lucene/search/TermRangeFilter.java
    lucene/java/trunk/src/java/org/apache/lucene/search/TopDocsCollector.java
    lucene/java/trunk/src/java/org/apache/lucene/search/TopFieldCollector.java
    lucene/java/trunk/src/java/org/apache/lucene/search/TopScoreDocCollector.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/FieldCacheImpl.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/FieldCacheImpl.java?rev=826857&r1=826856&r2=826857&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/FieldCacheImpl.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/FieldCacheImpl.java Mon Oct 19 22:59:06
2009
@@ -21,13 +21,10 @@
 import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
-import java.util.Locale;
 import java.util.Map;
 import java.util.WeakHashMap;
 
-import org.apache.lucene.document.NumericField; // javadoc
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermDocs;
@@ -45,12 +42,12 @@
  */
 class FieldCacheImpl implements FieldCache {
 	
-  private Map caches;
+  private Map<Class<?>,Cache> caches;
   FieldCacheImpl() {
     init();
   }
   private synchronized void init() {
-    caches = new HashMap(7);
+    caches = new HashMap<Class<?>,Cache>(7);
     caches.put(Byte.TYPE, new ByteCache(this));
     caches.put(Short.TYPE, new ShortCache(this));
     caches.put(Integer.TYPE, new IntCache(this));
@@ -66,23 +63,18 @@
   }
   
   public CacheEntry[] getCacheEntries() {
-    List result = new ArrayList(17);
-    Iterator outerKeys = caches.keySet().iterator();
-    while (outerKeys.hasNext()) {
-      Class cacheType = (Class)outerKeys.next();
-      Cache cache = (Cache)caches.get(cacheType);
-      Iterator innerKeys = cache.readerCache.keySet().iterator();
-      while (innerKeys.hasNext()) {
+    List<CacheEntry> result = new ArrayList<CacheEntry>(17);
+    for(final Class<?> cacheType: caches.keySet()) {
+      Cache cache = caches.get(cacheType);
+      for (final Object readerKey : cache.readerCache.keySet()) {
         // we've now materialized a hard ref
-        Object readerKey = innerKeys.next();
+        
         // innerKeys was backed by WeakHashMap, sanity check
         // that it wasn't GCed before we made hard ref
         if (null != readerKey && cache.readerCache.containsKey(readerKey)) {
-          Map innerCache = ((Map)cache.readerCache.get(readerKey));
-          Iterator entrySetIterator = innerCache.entrySet().iterator();
-          while (entrySetIterator.hasNext()) {
-            Map.Entry mapEntry = (Map.Entry) entrySetIterator.next();
-            Entry entry = (Entry) mapEntry.getKey();
+          Map<Entry, Object> innerCache = cache.readerCache.get(readerKey);
+          for (final Map.Entry<Entry, Object> mapEntry : innerCache.entrySet()) {
+            Entry entry = mapEntry.getKey();
             result.add(new CacheEntryImpl(readerKey, entry.field,
                                           cacheType, entry.custom,
                                           mapEntry.getValue()));
@@ -90,17 +82,17 @@
         }
       }
     }
-    return (CacheEntry[]) result.toArray(new CacheEntry[result.size()]);
+    return result.toArray(new CacheEntry[result.size()]);
   }
   
   private static final class CacheEntryImpl extends CacheEntry {
     private final Object readerKey;
     private final String fieldName;
-    private final Class cacheType;
+    private final Class<?> cacheType;
     private final Object custom;
     private final Object value;
     CacheEntryImpl(Object readerKey, String fieldName,
-                   Class cacheType,
+                   Class<?> cacheType,
                    Object custom,
                    Object value) {
         this.readerKey = readerKey;
@@ -117,7 +109,7 @@
     }
     public Object getReaderKey() { return readerKey; }
     public String getFieldName() { return fieldName; }
-    public Class getCacheType() { return cacheType; }
+    public Class<?> getCacheType() { return cacheType; }
     public Object getCustom() { return custom; }
     public Object getValue() { return value; }
   }
@@ -142,19 +134,19 @@
 
     final FieldCache wrapper;
 
-    final Map readerCache = new WeakHashMap();
+    final Map<Object,Map<Entry,Object>> readerCache = new WeakHashMap<Object,Map<Entry,Object>>();
     
     protected abstract Object createValue(IndexReader reader, Entry key)
         throws IOException;
 
     public Object get(IndexReader reader, Entry key) throws IOException {
-      Map innerCache;
+      Map<Entry,Object> innerCache;
       Object value;
       final Object readerKey = reader.getFieldCacheKey();
       synchronized (readerCache) {
-        innerCache = (Map) readerCache.get(readerKey);
+        innerCache = readerCache.get(readerKey);
         if (innerCache == null) {
-          innerCache = new HashMap();
+          innerCache = new HashMap<Entry,Object>();
           readerCache.put(readerKey, innerCache);
           value = null;
         } else {
@@ -248,7 +240,7 @@
   // inherit javadocs
   public byte[] getBytes(IndexReader reader, String field, ByteParser parser)
       throws IOException {
-    return (byte[]) ((Cache)caches.get(Byte.TYPE)).get(reader, new Entry(field, parser));
+    return (byte[]) caches.get(Byte.TYPE).get(reader, new Entry(field, parser));
   }
 
   static final class ByteCache extends Cache {
@@ -257,7 +249,7 @@
     }
     protected Object createValue(IndexReader reader, Entry entryKey)
         throws IOException {
-      Entry entry = (Entry) entryKey;
+      Entry entry = entryKey;
       String field = entry.field;
       ByteParser parser = (ByteParser) entry.custom;
       if (parser == null) {
@@ -293,7 +285,7 @@
   // inherit javadocs
   public short[] getShorts(IndexReader reader, String field, ShortParser parser)
       throws IOException {
-    return (short[]) ((Cache)caches.get(Short.TYPE)).get(reader, new Entry(field, parser));
+    return (short[]) caches.get(Short.TYPE).get(reader, new Entry(field, parser));
   }
 
   static final class ShortCache extends Cache {
@@ -303,7 +295,7 @@
 
     protected Object createValue(IndexReader reader, Entry entryKey)
         throws IOException {
-      Entry entry = (Entry) entryKey;
+      Entry entry =  entryKey;
       String field = entry.field;
       ShortParser parser = (ShortParser) entry.custom;
       if (parser == null) {
@@ -339,7 +331,7 @@
   // inherit javadocs
   public int[] getInts(IndexReader reader, String field, IntParser parser)
       throws IOException {
-    return (int[]) ((Cache)caches.get(Integer.TYPE)).get(reader, new Entry(field, parser));
+    return (int[]) caches.get(Integer.TYPE).get(reader, new Entry(field, parser));
   }
 
   static final class IntCache extends Cache {
@@ -349,7 +341,7 @@
 
     protected Object createValue(IndexReader reader, Entry entryKey)
         throws IOException {
-      Entry entry = (Entry) entryKey;
+      Entry entry = entryKey;
       String field = entry.field;
       IntParser parser = (IntParser) entry.custom;
       if (parser == null) {
@@ -396,7 +388,7 @@
   public float[] getFloats(IndexReader reader, String field, FloatParser parser)
     throws IOException {
 
-    return (float[]) ((Cache)caches.get(Float.TYPE)).get(reader, new Entry(field, parser));
+    return (float[]) caches.get(Float.TYPE).get(reader, new Entry(field, parser));
   }
 
   static final class FloatCache extends Cache {
@@ -406,7 +398,7 @@
 
     protected Object createValue(IndexReader reader, Entry entryKey)
         throws IOException {
-      Entry entry = (Entry) entryKey;
+      Entry entry = entryKey;
       String field = entry.field;
       FloatParser parser = (FloatParser) entry.custom;
       if (parser == null) {
@@ -450,7 +442,7 @@
   // inherit javadocs
   public long[] getLongs(IndexReader reader, String field, FieldCache.LongParser parser)
       throws IOException {
-    return (long[]) ((Cache)caches.get(Long.TYPE)).get(reader, new Entry(field, parser));
+    return (long[]) caches.get(Long.TYPE).get(reader, new Entry(field, parser));
   }
 
   static final class LongCache extends Cache {
@@ -505,7 +497,7 @@
   // inherit javadocs
   public double[] getDoubles(IndexReader reader, String field, FieldCache.DoubleParser parser)
       throws IOException {
-    return (double[]) ((Cache)caches.get(Double.TYPE)).get(reader, new Entry(field, parser));
+    return (double[]) caches.get(Double.TYPE).get(reader, new Entry(field, parser));
   }
 
   static final class DoubleCache extends Cache {
@@ -515,7 +507,7 @@
 
     protected Object createValue(IndexReader reader, Entry entryKey)
         throws IOException {
-      Entry entry = (Entry) entryKey;
+      Entry entry = entryKey;
       String field = entry.field;
       FieldCache.DoubleParser parser = (FieldCache.DoubleParser) entry.custom;
       if (parser == null) {
@@ -554,7 +546,7 @@
   // inherit javadocs
   public String[] getStrings(IndexReader reader, String field)
       throws IOException {
-    return (String[]) ((Cache)caches.get(String.class)).get(reader, new Entry(field, (Parser)null));
+    return (String[]) caches.get(String.class).get(reader, new Entry(field, (Parser)null));
   }
 
   static final class StringCache extends Cache {
@@ -589,7 +581,7 @@
   // inherit javadocs
   public StringIndex getStringIndex(IndexReader reader, String field)
       throws IOException {
-    return (StringIndex) ((Cache)caches.get(StringIndex.class)).get(reader, new Entry(field,
(Parser)null));
+    return (StringIndex) caches.get(StringIndex.class).get(reader, new Entry(field, (Parser)null));
   }
 
   static final class StringIndexCache extends Cache {

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/FieldValueHitQueue.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/FieldValueHitQueue.java?rev=826857&r1=826856&r2=826857&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/FieldValueHitQueue.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/FieldValueHitQueue.java Mon Oct 19
22:59:06 2009
@@ -34,7 +34,7 @@
  * @see Searcher#search(Query,Filter,int,Sort)
  * @see FieldCache
  */
-public abstract class FieldValueHitQueue extends PriorityQueue {
+public abstract class FieldValueHitQueue extends PriorityQueue<FieldValueHitQueue.Entry>
{
 
   final static class Entry {
     int slot;
@@ -84,9 +84,7 @@
      * @param b ScoreDoc
      * @return <code>true</code> if document <code>a</code> should
be sorted after document <code>b</code>.
      */
-    protected boolean lessThan(final Object a, final Object b) {
-      final Entry hitA = (Entry) a;
-      final Entry hitB = (Entry) b;
+    protected boolean lessThan(final Entry hitA, final Entry hitB) {
 
       assert hitA != hitB;
       assert hitA.slot != hitB.slot;
@@ -123,9 +121,7 @@
       initialize(size);
     }
   
-    protected boolean lessThan(final Object a, final Object b) {
-      final Entry hitA = (Entry) a;
-      final Entry hitB = (Entry) b;
+    protected boolean lessThan(final Entry hitA, final Entry hitB) {
 
       assert hitA != hitB;
       assert hitA.slot != hitB.slot;
@@ -194,7 +190,7 @@
   protected final FieldComparator[] comparators;
   protected final int[] reverseMul;
 
-  protected abstract boolean lessThan (final Object a, final Object b);
+  protected abstract boolean lessThan (final Entry a, final Entry b);
 
   /**
    * Given a queue Entry, creates a corresponding FieldDoc

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java?rev=826857&r1=826856&r2=826857&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java Mon
Oct 19 22:59:06 2009
@@ -39,14 +39,14 @@
  * {@link MultiTermQuery#CONSTANT_SCORE_FILTER_REWRITE};
  * this is why it is not abstract.
  */
-public class MultiTermQueryWrapperFilter extends Filter {
+public class MultiTermQueryWrapperFilter<Q extends MultiTermQuery> extends Filter {
     
-  protected final MultiTermQuery query;
+  protected final Q query;
 
   /**
    * Wrap a {@link MultiTermQuery} as a Filter.
    */
-  protected MultiTermQueryWrapperFilter(MultiTermQuery query) {
+  protected MultiTermQueryWrapperFilter(Q query) {
       this.query = query;
   }
   

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/NumericRangeFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/NumericRangeFilter.java?rev=826857&r1=826856&r2=826857&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/NumericRangeFilter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/NumericRangeFilter.java Mon Oct 19
22:59:06 2009
@@ -45,7 +45,7 @@
  *
  * @since 2.9
  **/
-public final class NumericRangeFilter<T extends Number> extends MultiTermQueryWrapperFilter
{
+public final class NumericRangeFilter<T extends Number> extends MultiTermQueryWrapperFilter<NumericRangeQuery<T>>
{
 
   private NumericRangeFilter(final NumericRangeQuery<T> query) {
     super(query);
@@ -172,23 +172,18 @@
   }
   
   /** Returns the field name for this filter */
-  @SuppressWarnings("unchecked")
-  public String getField() { return ((NumericRangeQuery<T>)query).getField(); }
+  public String getField() { return query.getField(); }
 
   /** Returns <code>true</code> if the lower endpoint is inclusive */
-  @SuppressWarnings("unchecked")
-  public boolean includesMin() { return ((NumericRangeQuery<T>)query).includesMin();
}
+  public boolean includesMin() { return query.includesMin(); }
   
   /** Returns <code>true</code> if the upper endpoint is inclusive */
-  @SuppressWarnings("unchecked")
-  public boolean includesMax() { return ((NumericRangeQuery<T>)query).includesMax();
}
+  public boolean includesMax() { return query.includesMax(); }
 
   /** Returns the lower value of this range filter */
-  @SuppressWarnings("unchecked")
-  public T getMin() { return ((NumericRangeQuery<T>)query).getMin(); }
+  public T getMin() { return query.getMin(); }
 
   /** Returns the upper value of this range filter */
-  @SuppressWarnings("unchecked")
-  public T getMax() { return ((NumericRangeQuery<T>)query).getMax(); }
+  public T getMax() { return query.getMax(); }
   
 }

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/PrefixFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/PrefixFilter.java?rev=826857&r1=826856&r2=826857&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/PrefixFilter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/PrefixFilter.java Mon Oct 19 22:59:06
2009
@@ -23,13 +23,13 @@
  * A Filter that restricts search results to values that have a matching prefix in a given
  * field.
  */
-public class PrefixFilter extends MultiTermQueryWrapperFilter {
+public class PrefixFilter extends MultiTermQueryWrapperFilter<PrefixQuery> {
 
   public PrefixFilter(Term prefix) {
     super(new PrefixQuery(prefix));
   }
 
-  public Term getPrefix() { return ((PrefixQuery)query).getPrefix(); }
+  public Term getPrefix() { return query.getPrefix(); }
 
   /** Prints a user-readable version of this query. */
   public String toString () {

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/TermRangeFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/TermRangeFilter.java?rev=826857&r1=826856&r2=826857&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/TermRangeFilter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/TermRangeFilter.java Mon Oct 19 22:59:06
2009
@@ -32,7 +32,7 @@
  * same field, {@link FieldCacheRangeFilter} may have significantly better performance. 
  * @since 2.9
  */
-public class TermRangeFilter extends MultiTermQueryWrapperFilter {
+public class TermRangeFilter extends MultiTermQueryWrapperFilter<TermRangeQuery> {
     
   /**
    * @param fieldName The field this range applies to
@@ -89,20 +89,20 @@
   }
 
   /** Returns the field name for this filter */
-  public String getField() { return ((TermRangeQuery) query).getField(); }
+  public String getField() { return query.getField(); }
   
   /** Returns the lower value of this range filter */
-  public String getLowerTerm() { return ((TermRangeQuery) query).getLowerTerm(); }
+  public String getLowerTerm() { return query.getLowerTerm(); }
 
   /** Returns the upper value of this range filter */
-  public String getUpperTerm() { return ((TermRangeQuery) query).getUpperTerm(); }
+  public String getUpperTerm() { return query.getUpperTerm(); }
   
   /** Returns <code>true</code> if the lower endpoint is inclusive */
-  public boolean includesLower() { return ((TermRangeQuery) query).includesLower(); }
+  public boolean includesLower() { return query.includesLower(); }
   
   /** Returns <code>true</code> if the upper endpoint is inclusive */
-  public boolean includesUpper() { return ((TermRangeQuery) query).includesUpper(); }
+  public boolean includesUpper() { return query.includesUpper(); }
 
   /** Returns the collator used to determine range inclusion, if any. */
-  public Collator getCollator() { return ((TermRangeQuery) query).getCollator(); }
+  public Collator getCollator() { return query.getCollator(); }
 }

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/TopDocsCollector.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/TopDocsCollector.java?rev=826857&r1=826856&r2=826857&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/TopDocsCollector.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/TopDocsCollector.java Mon Oct 19 22:59:06
2009
@@ -17,6 +17,7 @@
  * limitations under the License.
  */
 
+
 import org.apache.lucene.util.PriorityQueue;
 
 /**
@@ -27,7 +28,7 @@
  * Extending classes can override {@link #topDocs(int, int)} and
  * {@link #getTotalHits()} in order to provide their own implementation.
  */
-public abstract class TopDocsCollector extends Collector {
+public abstract class TopDocsCollector<T> extends Collector {
 
   // This is used in case topDocs() is called with illegal parameters, or there
   // simply aren't (enough) results.
@@ -39,12 +40,12 @@
    * HitQueue for example aggregates the top scoring documents, while other PQ
    * implementations may hold documents sorted by other criteria.
    */
-  protected PriorityQueue pq;
+  protected PriorityQueue<T> pq;
 
   /** The total number of documents that the collector encountered. */
   protected int totalHits;
   
-  protected TopDocsCollector(PriorityQueue pq) {
+  protected TopDocsCollector(PriorityQueue<T> pq) {
     this.pq = pq;
   }
   

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/TopFieldCollector.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/TopFieldCollector.java?rev=826857&r1=826856&r2=826857&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/TopFieldCollector.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/TopFieldCollector.java Mon Oct 19
22:59:06 2009
@@ -33,7 +33,7 @@
  * <p><b>NOTE:</b> This API is experimental and might change in
  * incompatible ways in the next release.</p>
  */
-public abstract class TopFieldCollector extends TopDocsCollector {
+public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
   
   // TODO: one optimization we could do is to pre-fill
   // the queue with sentinel value that guaranteed to
@@ -60,7 +60,7 @@
     final void updateBottom(int doc) {
       // bottom.score is already set to Float.NaN in add().
       bottom.docID = docBase + doc;
-      bottom = (Entry) pq.updateTop();
+      bottom = pq.updateTop();
     }
 
     public void collect(int doc) throws IOException {
@@ -161,7 +161,7 @@
     final void updateBottom(int doc, float score) {
       bottom.docID = docBase + doc;
       bottom.score = score;
-      bottom = (Entry) pq.updateTop();
+      bottom = pq.updateTop();
     }
 
     public void collect(int doc) throws IOException {
@@ -273,7 +273,7 @@
     final void updateBottom(int doc, float score) {
       bottom.docID = docBase + doc;
       bottom.score = score;
-      bottom = (Entry) pq.updateTop();
+      bottom =  pq.updateTop();
     }
 
     public void collect(int doc) throws IOException {
@@ -380,7 +380,7 @@
     final void updateBottom(int doc) {
       // bottom.score is already set to Float.NaN in add().
       bottom.docID = docBase + doc;
-      bottom = (Entry) pq.updateTop();
+      bottom = pq.updateTop();
     }
 
     public void collect(int doc) throws IOException {
@@ -529,7 +529,7 @@
     final void updateBottom(int doc, float score) {
       bottom.docID = docBase + doc;
       bottom.score = score;
-      bottom = (Entry) pq.updateTop();
+      bottom =  pq.updateTop();
     }
 
     public void collect(int doc) throws IOException {
@@ -675,7 +675,7 @@
     final void updateBottom(int doc, float score) {
       bottom.docID = docBase + doc;
       bottom.score = score;
-      bottom = (Entry) pq.updateTop();
+      bottom = pq.updateTop();
     }
 
     public void collect(int doc) throws IOException {
@@ -833,7 +833,7 @@
   // internal versions. If someone will define a constructor with any other
   // visibility, then anyone will be able to extend the class, which is not what
   // we want.
-  private TopFieldCollector(PriorityQueue pq, int numHits, boolean fillFields) {
+  private TopFieldCollector(PriorityQueue<Entry> pq, int numHits, boolean fillFields)
{
     super(pq);
     this.numHits = numHits;
     this.fillFields = fillFields;
@@ -925,7 +925,7 @@
   }
   
   final void add(int slot, int doc, float score) {
-    bottom = (Entry) pq.add(new Entry(slot, docBase + doc, score));
+    bottom = pq.add(new Entry(slot, docBase + doc, score));
     queueFull = totalHits == numHits;
   }
 
@@ -943,7 +943,7 @@
       }
     } else {
       for (int i = howMany - 1; i >= 0; i--) {
-        Entry entry = (Entry) pq.pop();
+        Entry entry = pq.pop();
         results[i] = new FieldDoc(entry.docID, entry.score);
       }
     }

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/TopScoreDocCollector.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/TopScoreDocCollector.java?rev=826857&r1=826856&r2=826857&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/TopScoreDocCollector.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/TopScoreDocCollector.java Mon Oct
19 22:59:06 2009
@@ -34,7 +34,7 @@
  * not valid scores.  This collector will not properly
  * collect hits with such scores.
  */
-public abstract class TopScoreDocCollector extends TopDocsCollector {
+public abstract class TopScoreDocCollector extends TopDocsCollector<ScoreDoc> {
 
   // Assumes docs are scored in order.
   private static class InOrderTopScoreDocCollector extends TopScoreDocCollector {
@@ -53,7 +53,7 @@
       }
       pqTop.doc = doc + docBase;
       pqTop.score = score;
-      pqTop = (ScoreDoc) pq.updateTop();
+      pqTop = pq.updateTop();
     }
     
     public boolean acceptsDocsOutOfOrder() {
@@ -76,7 +76,7 @@
       }
       pqTop.doc = doc;
       pqTop.score = score;
-      pqTop = (ScoreDoc) pq.updateTop();
+      pqTop = pq.updateTop();
     }
     
     public boolean acceptsDocsOutOfOrder() {
@@ -113,7 +113,7 @@
     super(new HitQueue(numHits, true));
     // HitQueue implements getSentinelObject to return a ScoreDoc, so we know
     // that at this point top() is already initialized.
-    pqTop = (ScoreDoc) pq.top();
+    pqTop = pq.top();
   }
 
   protected TopDocs newTopDocs(ScoreDoc[] results, int start) {
@@ -130,7 +130,7 @@
       maxScore = results[0].score;
     } else {
       for (int i = pq.size(); i > 1; i--) { pq.pop(); }
-      maxScore = ((ScoreDoc) pq.pop()).score;
+      maxScore = pq.pop().score;
     }
     
     return new TopDocs(totalHits, results, maxScore);



Mime
View raw message