mirror of https://github.com/apache/lucene.git
LUCENE-2006: Optimization for FieldDocSortedHitQueue
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@829274 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7902c4b729
commit
6f6afbe1bc
11
CHANGES.txt
11
CHANGES.txt
|
@ -137,10 +137,13 @@ Optimizations
|
||||||
* LUCENE-1183: Optimize Levenshtein Distance computation in
|
* LUCENE-1183: Optimize Levenshtein Distance computation in
|
||||||
FuzzyQuery. (Cédrik Lime via Mike McCandless)
|
FuzzyQuery. (Cédrik Lime via Mike McCandless)
|
||||||
|
|
||||||
* LUCENE-2002: Add required Version matchVersion argument when
|
* LUCENE-2002: Add required Version matchVersion argument when
|
||||||
constructing QueryParser or MultiFieldQueryParser and, default (as
|
constructing QueryParser or MultiFieldQueryParser and, default (as
|
||||||
of 2.9) enablePositionIncrements to true to match
|
of 2.9) enablePositionIncrements to true to match
|
||||||
StandardAnalyzer's 2.9 default (Uwe Schindler, Mike McCandless)
|
StandardAnalyzer's 2.9 default (Uwe Schindler, Mike McCandless)
|
||||||
|
|
||||||
|
* LUCENE-2006: Optimization of FieldDocSortedHitQueue to always
|
||||||
|
use Comparable<?> interface. (Uwe Schindler, Mark Miller)
|
||||||
|
|
||||||
Documentation
|
Documentation
|
||||||
|
|
||||||
|
|
|
@ -100,80 +100,28 @@ class FieldDocSortedHitQueue extends PriorityQueue<FieldDoc> {
|
||||||
int c = 0;
|
int c = 0;
|
||||||
for (int i=0; i<n && c==0; ++i) {
|
for (int i=0; i<n && c==0; ++i) {
|
||||||
final int type = fields[i].getType();
|
final int type = fields[i].getType();
|
||||||
switch (type) {
|
if (type == SortField.STRING) {
|
||||||
case SortField.SCORE:{
|
final String s1 = (String) docA.fields[i];
|
||||||
float r1 = ((Float)docA.fields[i]).floatValue();
|
final String s2 = (String) docB.fields[i];
|
||||||
float r2 = ((Float)docB.fields[i]).floatValue();
|
// null values need to be sorted first, because of how FieldCache.getStringIndex()
|
||||||
if (r1 > r2) c = -1;
|
// works - in that routine, any documents without a value in the given field are
|
||||||
if (r1 < r2) c = 1;
|
// put first. If both are null, the next SortField is used
|
||||||
break;
|
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);
|
||||||
}
|
}
|
||||||
case SortField.DOC:
|
} else {
|
||||||
case SortField.INT:{
|
// the casts are a no-ops, its only there to make the
|
||||||
int i1 = ((Integer)docA.fields[i]).intValue();
|
// compiler happy because of unbounded generics:
|
||||||
int i2 = ((Integer)docB.fields[i]).intValue();
|
c = ((Comparable) docA.fields[i]).compareTo((Comparable) docB.fields[i]);
|
||||||
if (i1 < i2) c = -1;
|
if (type == SortField.SCORE) {
|
||||||
if (i1 > i2) c = 1;
|
c = -c;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// reverse sort
|
||||||
if (fields[i].getReverse()) {
|
if (fields[i].getReverse()) {
|
||||||
c = -c;
|
c = -c;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue