constants - only do more expensive conversions once... adds up over an entire index

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@883522 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2009-11-23 22:17:39 +00:00
parent 22ce12d324
commit c812e9fc5b
2 changed files with 19 additions and 9 deletions

View File

@ -555,9 +555,13 @@ class DateValueSourceParser extends ValueSourceParser {
// Private for now - we need to revisit how to handle typing in function queries
class LongConstValueSource extends ValueSource {
final long constant;
final double dv;
final float fv;
public LongConstValueSource(long constant) {
this.constant = constant;
this.dv = constant;
this.fv = constant;
}
public String description() {
@ -567,7 +571,7 @@ class LongConstValueSource extends ValueSource {
public DocValues getValues(Map context, IndexReader reader) throws IOException {
return new DocValues() {
public float floatVal(int doc) {
return constant;
return fv;
}
public int intVal(int doc) {
@ -579,7 +583,7 @@ class LongConstValueSource extends ValueSource {
}
public double doubleVal(int doc) {
return constant;
return dv;
}
public String strVal(int doc) {
@ -606,9 +610,13 @@ class LongConstValueSource extends ValueSource {
// Private for now - we need to revisit how to handle typing in function queries
class DoubleConstValueSource extends ValueSource {
final double constant;
private final float fv;
private final long lv;
public DoubleConstValueSource(double constant) {
this.constant = constant;
this.fv = (float)constant;
this.lv = (long)constant;
}
public String description() {
@ -618,15 +626,15 @@ class DoubleConstValueSource extends ValueSource {
public DocValues getValues(Map context, IndexReader reader) throws IOException {
return new DocValues() {
public float floatVal(int doc) {
return (float)constant;
return fv;
}
public int intVal(int doc) {
return (int) constant;
return (int) lv;
}
public long longVal(int doc) {
return (long)constant;
return lv;
}
public double doubleVal(int doc) {

View File

@ -27,9 +27,11 @@ import java.util.Map;
*/
public class ConstValueSource extends ValueSource {
final float constant;
private final double dv;
public ConstValueSource(float constant) {
this.constant = constant;
this.dv = constant;
}
public String description() {
@ -42,16 +44,16 @@ public class ConstValueSource extends ValueSource {
return constant;
}
public int intVal(int doc) {
return (int)floatVal(doc);
return (int)constant;
}
public long longVal(int doc) {
return (long)floatVal(doc);
return (long)constant;
}
public double doubleVal(int doc) {
return (double)floatVal(doc);
return dv;
}
public String strVal(int doc) {
return Float.toString(floatVal(doc));
return Float.toString(constant);
}
public String toString(int doc) {
return description();