lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r829274 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/search/FieldDocSortedHitQueue.java
Date Fri, 23 Oct 2009 23:09:49 GMT
Author: uschindler
Date: Fri Oct 23 23:09:49 2009
New Revision: 829274

URL: http://svn.apache.org/viewvc?rev=829274&view=rev
Log:
LUCENE-2006: Optimization for FieldDocSortedHitQueue

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/search/FieldDocSortedHitQueue.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=829274&r1=829273&r2=829274&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Fri Oct 23 23:09:49 2009
@@ -137,10 +137,13 @@
 * LUCENE-1183: Optimize Levenshtein Distance computation in
   FuzzyQuery.  (Cédrik Lime via Mike McCandless)
 
- * LUCENE-2002: Add required Version matchVersion argument when
-   constructing QueryParser or MultiFieldQueryParser and, default (as
-   of 2.9) enablePositionIncrements to true to match
-   StandardAnalyzer's 2.9 default (Uwe Schindler, Mike McCandless)
+* LUCENE-2002: Add required Version matchVersion argument when
+  constructing QueryParser or MultiFieldQueryParser and, default (as
+  of 2.9) enablePositionIncrements to true to match
+  StandardAnalyzer's 2.9 default (Uwe Schindler, Mike McCandless)
+
+* LUCENE-2006: Optimization of FieldDocSortedHitQueue to always
+  use Comparable<?> interface.  (Uwe Schindler, Mark Miller)
 
 Documentation
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/FieldDocSortedHitQueue.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/FieldDocSortedHitQueue.java?rev=829274&r1=829273&r2=829274&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/FieldDocSortedHitQueue.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/FieldDocSortedHitQueue.java Fri Oct
23 23:09:49 2009
@@ -100,80 +100,28 @@
     int c = 0;
     for (int i=0; i<n && c==0; ++i) {
       final int type = fields[i].getType();
-      switch (type) {
-        case SortField.SCORE:{
-          float r1 = ((Float)docA.fields[i]).floatValue();
-          float r2 = ((Float)docB.fields[i]).floatValue();
-          if (r1 > r2) c = -1;
-          if (r1 < r2) c = 1;
-          break;
-        }
-        case SortField.DOC:
-        case SortField.INT:{
-          int i1 = ((Integer)docA.fields[i]).intValue();
-          int i2 = ((Integer)docB.fields[i]).intValue();
-          if (i1 < i2) c = -1;
-          if (i1 > i2) c = 1;
-          break;
-        }
-        case SortField.LONG:{
-          long l1 = ((Long)docA.fields[i]).longValue();
-          long l2 = ((Long)docB.fields[i]).longValue();
-          if (l1 < l2) c = -1;
-          if (l1 > l2) c = 1;
-          break;
-        }
-        case SortField.STRING:{
-          String s1 = (String) docA.fields[i];
-          String s2 = (String) docB.fields[i];
-          // null values need to be sorted first, because of how FieldCache.getStringIndex()
-          // works - in that routine, any documents without a value in the given field are
-          // put first.  If both are null, the next SortField is used
-          if (s1 == null) c = (s2==null) ? 0 : -1;
-          else if (s2 == null) c = 1;  // 
-          else if (fields[i].getLocale() == null) {
-            c = s1.compareTo(s2);
-          } else {
-            c = collators[i].compare (s1, s2);
-          }
-          break;
-        }
-        case SortField.FLOAT:{
-          float f1 = ((Float)docA.fields[i]).floatValue();
-          float f2 = ((Float)docB.fields[i]).floatValue();
-          if (f1 < f2) c = -1;
-          if (f1 > f2) c = 1;
-          break;
-        }
-        case SortField.DOUBLE:{
-          double d1 = ((Double)docA.fields[i]).doubleValue();
-          double d2 = ((Double)docB.fields[i]).doubleValue();
-          if (d1 < d2) c = -1;
-          if (d1 > d2) c = 1;
-          break;
-        }
-        case SortField.BYTE:{
-          int i1 = ((Byte)docA.fields[i]).byteValue();
-          int i2 = ((Byte)docB.fields[i]).byteValue();
-          if (i1 < i2) c = -1;
-          if (i1 > i2) c = 1;
-          break;
-        }
-        case SortField.SHORT:{
-          int i1 = ((Short)docA.fields[i]).shortValue();
-          int i2 = ((Short)docB.fields[i]).shortValue();
-          if (i1 < i2) c = -1;
-          if (i1 > i2) c = 1;
-          break;
-        }
-        case SortField.CUSTOM:{
-          c = ((Comparable) docA.fields[i]).compareTo((Comparable) docB.fields[i]);
-          break;
-        }
-        default:{
-          throw new RuntimeException ("invalid SortField type: "+type);
+      if (type == SortField.STRING) {
+        final String s1 = (String) docA.fields[i];
+        final String s2 = (String) docB.fields[i];
+        // null values need to be sorted first, because of how FieldCache.getStringIndex()
+        // works - in that routine, any documents without a value in the given field are
+        // put first.  If both are null, the next SortField is used
+        if (s1 == null) c = (s2==null) ? 0 : -1;
+        else if (s2 == null) c = 1;  // 
+        else if (fields[i].getLocale() == null) {
+          c = s1.compareTo(s2);
+        } else {
+          c = collators[i].compare(s1, s2);
+        }
+      } else {
+        // the casts are a no-ops, its only there to make the
+        // compiler happy because of unbounded generics:
+        c = ((Comparable) docA.fields[i]).compareTo((Comparable) docB.fields[i]);
+        if (type == SortField.SCORE) {
+          c = -c;
         }
       }
+      // reverse sort
       if (fields[i].getReverse()) {
         c = -c;
       }



Mime
View raw message