lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r1092812 [1/2] - in /lucene/dev/trunk/solr/src: java/org/apache/solr/handler/ java/org/apache/solr/response/transform/ java/org/apache/solr/schema/ java/org/apache/solr/search/ java/org/apache/solr/search/function/ java/org/apache/solr/sear...
Date Fri, 15 Apr 2011 21:13:43 GMT
Author: yonik
Date: Fri Apr 15 21:13:42 2011
New Revision: 1092812

URL: http://svn.apache.org/viewvc?rev=1092812&view=rev
Log:
SOLR-2469: remove saveCommitPoint for replicate on startup

Added:
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DoubleDocValues.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/FloatDocValues.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/IntDocValues.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/LongDocValues.java   (with props)
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/StrDocValues.java   (with props)
Modified:
    lucene/dev/trunk/solr/src/java/org/apache/solr/handler/ReplicationHandler.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/response/transform/ValueSourceAugmenter.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/schema/DateField.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/schema/RandomSortField.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SortableDoubleField.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SortableFloatField.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SortableIntField.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SortableLongField.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/schema/StrFieldSource.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/schema/TrieField.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/QueryParsing.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/ValueSourceParser.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ByteFieldSource.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ConstValueSource.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DocFreqValueSource.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DocValues.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DoubleConstValueSource.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DoubleFieldSource.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DualFloatFunction.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/FileFloatSource.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/FloatFieldSource.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/IntFieldSource.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/JoinDocFreqValueSource.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/LinearFloatFunction.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/LiteralValueSource.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/LongFieldSource.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/MultiFloatFunction.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/OrdFieldSource.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/QueryValueSource.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/RangeMapFloatFunction.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ReciprocalFloatFunction.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ReverseOrdFieldSource.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ScaleFloatFunction.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/SimpleFloatFunction.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/StringIndexDocValues.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/GeohashHaversineFunction.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/HaversineConstFunction.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/HaversineFunction.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/StringDistanceFunction.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/VectorDistanceFunction.java
    lucene/dev/trunk/solr/src/test/org/apache/solr/search/QueryParsingTest.java
    lucene/dev/trunk/solr/src/test/org/apache/solr/search/TestQueryTypes.java

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/handler/ReplicationHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/handler/ReplicationHandler.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/handler/ReplicationHandler.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/handler/ReplicationHandler.java Fri Apr 15 21:13:42 2011
@@ -843,9 +843,13 @@ public class ReplicationHandler extends 
                 indexCommitPoint = reader.getIndexCommit();
               }
             } finally {
+              // We don't need to save commit points for replication, the SolrDeletionPolicy
+              // always saves the last commit point (and the last optimized commit point, if needed)
+              /***
               if(indexCommitPoint != null){
                 core.getDeletionPolicy().saveCommitPoint(indexCommitPoint.getVersion());
               }
+              ***/
             }
           }
           if (core.getUpdateHandler() instanceof DirectUpdateHandler2) {

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/response/transform/ValueSourceAugmenter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/response/transform/ValueSourceAugmenter.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/response/transform/ValueSourceAugmenter.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/response/transform/ValueSourceAugmenter.java Fri Apr 15 21:13:42 2011
@@ -90,9 +90,10 @@ public class ValueSourceAugmenter extend
       }
 
       int localId = docid - rcontext.docBase;
-      float val = values.floatVal(localId);  // TODO: handle all types -- see: SOLR-2443
-
-      doc.setField( name, val );
+      Object val = values.objectVal(localId);
+      if (val != null) {
+        doc.setField( name, val );
+      }
     } catch (IOException e) {
       throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "exception at docid " + docid + " for valuesource " + valueSource, e, false);
     }

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/schema/DateField.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/schema/DateField.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/schema/DateField.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/schema/DateField.java Fri Apr 15 21:13:42 2011
@@ -487,6 +487,17 @@ class DateFieldSource extends FieldCache
       }
 
       @Override
+      public Object objectVal(int doc) {
+        int ord=termsIndex.getOrd(doc);
+        if (ord == 0) {
+          return null;
+        } else {
+          BytesRef br = termsIndex.lookup(ord, new BytesRef());
+          return ft.toObject(null, br);
+        }
+      }
+
+      @Override
       public String toString(int doc) {
         return description() + '=' + intVal(doc);
       }

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/schema/RandomSortField.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/schema/RandomSortField.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/schema/RandomSortField.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/schema/RandomSortField.java Fri Apr 15 21:13:42 2011
@@ -28,6 +28,7 @@ import org.apache.lucene.util.ReaderUtil
 import org.apache.solr.response.TextResponseWriter;
 import org.apache.solr.search.QParser;
 import org.apache.solr.search.function.DocValues;
+import org.apache.solr.search.function.IntDocValues;
 import org.apache.solr.search.function.ValueSource;
 
 /**
@@ -157,37 +158,12 @@ public class RandomSortField extends Fie
 
     @Override
     public DocValues getValues(Map context, final AtomicReaderContext readerContext) throws IOException {
-      return new DocValues() {
+      return new IntDocValues(this) {
           private final int seed = getSeed(field, readerContext);
           @Override
-          public float floatVal(int doc) {
-            return (float)hash(doc+seed);
-          }
-
-          @Override
           public int intVal(int doc) {
             return hash(doc+seed);
           }
-
-          @Override
-          public long longVal(int doc) {
-            return (long)hash(doc+seed);
-          }
-
-          @Override
-          public double doubleVal(int doc) {
-            return (double)hash(doc+seed);
-          }
-
-          @Override
-          public String strVal(int doc) {
-            return Integer.toString(hash(doc+seed));
-          }
-
-          @Override
-          public String toString(int doc) {
-            return description() + '=' + intVal(doc);
-          }
         };
     }
 

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SortableDoubleField.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SortableDoubleField.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SortableDoubleField.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SortableDoubleField.java Fri Apr 15 21:13:42 2011
@@ -149,6 +149,12 @@ class SortableDoubleFieldSource extends 
       }
 
       @Override
+      public Object objectVal(int doc) {
+        int ord=termsIndex.getOrd(doc);
+        return ord==0 ? null  : NumberUtils.SortableStr2double(termsIndex.lookup(ord, spare));
+      }
+
+      @Override
       public String toString(int doc) {
         return description() + '=' + doubleVal(doc);
       }

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SortableFloatField.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SortableFloatField.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SortableFloatField.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SortableFloatField.java Fri Apr 15 21:13:42 2011
@@ -154,6 +154,12 @@ class SortableFloatFieldSource extends F
       }
 
       @Override
+      public Object objectVal(int doc) {
+        int ord=termsIndex.getOrd(doc);
+        return ord==0 ? null  : NumberUtils.SortableStr2float(termsIndex.lookup(ord, spare));
+      }
+
+      @Override
       public ValueFiller getValueFiller() {
         return new ValueFiller() {
           private final MutableValueFloat mval = new MutableValueFloat();

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SortableIntField.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SortableIntField.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SortableIntField.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SortableIntField.java Fri Apr 15 21:13:42 2011
@@ -156,6 +156,12 @@ class SortableIntFieldSource extends Fie
       }
 
       @Override
+      public Object objectVal(int doc) {
+        int ord=termsIndex.getOrd(doc);
+        return ord==0 ? null  : NumberUtils.SortableStr2int(termsIndex.lookup(ord, spare));
+      }
+
+      @Override
       public ValueFiller getValueFiller() {
         return new ValueFiller() {
           private final MutableValueInt mval = new MutableValueInt();

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SortableLongField.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SortableLongField.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SortableLongField.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/schema/SortableLongField.java Fri Apr 15 21:13:42 2011
@@ -150,6 +150,12 @@ class SortableLongFieldSource extends Fi
       }
 
       @Override
+      public Object objectVal(int doc) {
+        int ord=termsIndex.getOrd(doc);
+        return ord==0 ? null  : NumberUtils.SortableStr2long(termsIndex.lookup(ord, spare));
+      }
+
+      @Override
       public String toString(int doc) {
         return description() + '=' + longVal(doc);
       }

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/schema/StrFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/schema/StrFieldSource.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/schema/StrFieldSource.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/schema/StrFieldSource.java Fri Apr 15 21:13:42 2011
@@ -19,9 +19,11 @@ package org.apache.solr.schema;
 
 import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.lucene.util.BytesRef;
+import org.apache.noggit.CharArr;
 import org.apache.solr.search.function.DocValues;
 import org.apache.solr.search.function.FieldCacheSource;
 import org.apache.solr.search.function.StringIndexDocValues;
+import org.apache.solr.util.ByteUtils;
 
 import java.io.IOException;
 import java.util.Map;
@@ -40,33 +42,13 @@ public class StrFieldSource extends Fiel
   @Override
   public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
     return new StringIndexDocValues(this, readerContext, field) {
+
       @Override
       protected String toTerm(String readableValue) {
         return readableValue;
       }
 
       @Override
-      public float floatVal(int doc) {
-        return (float)intVal(doc);
-      }
-
-      @Override
-      public int intVal(int doc) {
-        int ord=termsIndex.getOrd(doc);
-        return ord;
-      }
-
-      @Override
-      public long longVal(int doc) {
-        return (long)intVal(doc);
-      }
-
-      @Override
-      public double doubleVal(int doc) {
-        return (double)intVal(doc);
-      }
-
-      @Override
       public int ordVal(int doc) {
         return termsIndex.getOrd(doc);
       }
@@ -77,13 +59,8 @@ public class StrFieldSource extends Fiel
       }
 
       @Override
-      public String strVal(int doc) {
-        int ord=termsIndex.getOrd(doc);
-        if (ord == 0) {
-          return null;
-        } else {
-          return termsIndex.lookup(ord, new BytesRef()).utf8ToString();
-        }
+      public Object objectVal(int doc) {
+        return strVal(doc);
       }
 
       @Override

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/schema/TrieField.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/schema/TrieField.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/schema/TrieField.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/schema/TrieField.java Fri Apr 15 21:13:42 2011
@@ -539,6 +539,11 @@ class TrieDateFieldSource extends LongFi
   }
 
   @Override
+  public Object longToObject(long val) {
+    return new Date(val);
+  }
+
+  @Override
   public long externalToLong(String extVal) {
     return TrieField.dateField.parseMath(null, extVal).getTime();
   }

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/QueryParsing.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/QueryParsing.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/QueryParsing.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/QueryParsing.java Fri Apr 15 21:13:42 2011
@@ -638,7 +638,11 @@ public class QueryParsing {
       }
 
       String v = val.substring(start,pos);
-      return flt ? Double.parseDouble(v) : Long.parseLong(v);
+      if (flt) {
+        return Double.parseDouble(v);
+      } else {
+        return Long.parseLong(v);
+      }
     }
 
     double getDouble() throws ParseException {

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/ValueSourceParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/ValueSourceParser.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/ValueSourceParser.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/ValueSourceParser.java Fri Apr 15 21:13:42 2011
@@ -793,7 +793,7 @@ class LongConstValueSource extends Const
 
   @Override
   public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
-    return new DocValues() {
+    return new LongDocValues(this) {
       @Override
       public float floatVal(int doc) {
         return fv;
@@ -815,11 +815,6 @@ class LongConstValueSource extends Const
       }
 
       @Override
-      public String strVal(int doc) {
-        return Long.toString(constant);
-      }
-
-      @Override
       public String toString(int doc) {
         return description();
       }
@@ -901,28 +896,12 @@ abstract class DoubleParser extends Name
     @Override
     public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
       final DocValues vals =  source.getValues(context, readerContext);
-      return new DocValues() {
-        @Override
-        public float floatVal(int doc) {
-          return (float)doubleVal(doc);
-        }
-        @Override
-        public int intVal(int doc) {
-          return (int)doubleVal(doc);
-        }
-        @Override
-        public long longVal(int doc) {
-          return (long)doubleVal(doc);
-        }
+      return new DoubleDocValues(this) {
         @Override
         public double doubleVal(int doc) {
           return func(doc, vals);
         }
         @Override
-        public String strVal(int doc) {
-          return Double.toString(doubleVal(doc));
-        }
-        @Override
         public String toString(int doc) {
           return name() + '(' + vals.toString(doc) + ')';
         }
@@ -966,28 +945,12 @@ abstract class Double2Parser extends Nam
     public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
       final DocValues aVals =  a.getValues(context, readerContext);
       final DocValues bVals =  b.getValues(context, readerContext);
-      return new DocValues() {
-        @Override
-        public float floatVal(int doc) {
-          return (float)doubleVal(doc);
-        }
-        @Override
-        public int intVal(int doc) {
-          return (int)doubleVal(doc);
-        }
-        @Override
-        public long longVal(int doc) {
-          return (long)doubleVal(doc);
-        }
-        @Override
+      return new DoubleDocValues(this) {
+         @Override
         public double doubleVal(int doc) {
           return func(doc, aVals, bVals);
         }
         @Override
-        public String strVal(int doc) {
-          return Double.toString(doubleVal(doc));
-        }
-        @Override
         public String toString(int doc) {
           return name() + '(' + aVals.toString(doc) + ',' + bVals.toString(doc) + ')';
         }

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ByteFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ByteFieldSource.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ByteFieldSource.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ByteFieldSource.java Fri Apr 15 21:13:42 2011
@@ -88,6 +88,11 @@ public class ByteFieldSource extends Num
         return description() + '=' + byteVal(doc);
       }
 
+      @Override
+      public Object objectVal(int doc) {
+        return arr[doc];  // TODO: valid?
+      }
+
     };
   }
 }

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ConstValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ConstValueSource.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ConstValueSource.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ConstValueSource.java Fri Apr 15 21:13:42 2011
@@ -41,7 +41,7 @@ public class ConstValueSource extends Co
 
   @Override
   public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
-    return new DocValues() {
+    return new FloatDocValues(this) {
       @Override
       public float floatVal(int doc) {
         return constant;
@@ -59,13 +59,13 @@ public class ConstValueSource extends Co
         return dv;
       }
       @Override
-      public String strVal(int doc) {
-        return Float.toString(constant);
-      }
-      @Override
       public String toString(int doc) {
         return description();
       }
+      @Override
+      public Object objectVal(int doc) {
+        return constant;
+      }
     };
   }
 

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DocFreqValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DocFreqValueSource.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DocFreqValueSource.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DocFreqValueSource.java Fri Apr 15 21:13:42 2011
@@ -21,14 +21,13 @@ import org.apache.lucene.index.IndexRead
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.util.BytesRef;
-import org.apache.solr.search.MutableValueInt;
-import org.apache.solr.search.MutableValue;
+import org.apache.solr.search.*;
 
 import java.io.IOException;
 import java.util.Map;
 
 
-class ConstIntDocValues extends DocValues {
+class ConstIntDocValues extends IntDocValues {
   final int ival;
   final float fval;
   final double dval;
@@ -37,6 +36,7 @@ class ConstIntDocValues extends DocValue
   final ValueSource parent;
 
   ConstIntDocValues(int val, ValueSource parent) {
+    super(parent);
     ival = val;
     fval = val;
     dval = val;
@@ -71,7 +71,7 @@ class ConstIntDocValues extends DocValue
   }
 }
 
-class ConstDoubleDocValues extends DocValues {
+class ConstDoubleDocValues extends DoubleDocValues {
   final int ival;
   final float fval;
   final double dval;
@@ -80,6 +80,7 @@ class ConstDoubleDocValues extends DocVa
   final ValueSource parent;
 
   ConstDoubleDocValues(double val, ValueSource parent) {
+    super(parent);
     ival = (int)val;
     fval = (float)val;
     dval = val;
@@ -114,115 +115,6 @@ class ConstDoubleDocValues extends DocVa
   }
 }
 
-abstract class FloatDocValues extends DocValues {
-  protected final ValueSource vs;
-
-  public FloatDocValues(ValueSource vs) {
-    this.vs = vs;    
-  }
-
-  @Override
-  public byte byteVal(int doc) {
-    return (byte)floatVal(doc);
-  }
-
-  @Override
-  public short shortVal(int doc) {
-    return (short)floatVal(doc);
-  }
-
-  @Override
-  public abstract float floatVal(int doc);
-
-  @Override
-  public int intVal(int doc) {
-    return (int)floatVal(doc);
-  }
-
-  @Override
-  public long longVal(int doc) {
-    return (long)floatVal(doc);
-  }
-
-  @Override
-  public double doubleVal(int doc) {
-    return (double)floatVal(doc);
-  }
-
-  @Override
-  public String strVal(int doc) {
-    return Float.toString(floatVal(doc));
-  }
-
-  @Override
-  public String toString(int doc) {
-    return vs.description() + '=' + strVal(doc);
-  }
-}
-
-abstract class IntDocValues extends DocValues {
-  protected final ValueSource vs;
-
-  public IntDocValues(ValueSource vs) {
-    this.vs = vs;
-  }
-
-  @Override
-  public byte byteVal(int doc) {
-    return (byte)intVal(doc);
-  }
-
-  @Override
-  public short shortVal(int doc) {
-    return (short)intVal(doc);
-  }
-
-  @Override
-  public float floatVal(int doc) {
-    return (float)intVal(doc);
-  }
-
-  @Override
-  public abstract int intVal(int doc);
-
-  @Override
-  public long longVal(int doc) {
-    return (long)intVal(doc);
-  }
-
-  @Override
-  public double doubleVal(int doc) {
-    return (double)intVal(doc);
-  }
-
-  @Override
-  public String strVal(int doc) {
-    return Integer.toString(intVal(doc));
-  }
-
-  @Override
-  public String toString(int doc) {
-    return vs.description() + '=' + strVal(doc);
-  }
-
-  @Override
-  public ValueFiller getValueFiller() {
-    return new ValueFiller() {
-      private final MutableValueInt mval = new MutableValueInt();
-
-      @Override
-      public MutableValue getValue() {
-        return mval;
-      }
-
-      @Override
-      public void fillValue(int doc) {
-        mval.value = intVal(doc);
-      }
-    };
-  }
-}
-
 
 /**
  * <code>DocFreqValueSource</code> returns the number of documents containing the term.

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DocValues.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DocValues.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DocValues.java Fri Apr 15 21:13:42 2011
@@ -19,6 +19,7 @@ package org.apache.solr.search.function;
 
 import org.apache.lucene.search.*;
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.util.BytesRef;
 import org.apache.solr.search.MutableValue;
 import org.apache.solr.search.MutableValueFloat;
 
@@ -47,6 +48,28 @@ public abstract class DocValues {
   // TODO: should we make a termVal, returns BytesRef?
   public String strVal(int doc) { throw new UnsupportedOperationException(); }
 
+  /** returns the bytes representation of the string val - TODO: should this return the indexed raw bytes not? */
+  public boolean bytesVal(int doc, BytesRef target) {
+    String s = strVal(doc);
+    if (s==null) {
+      target.length = 0;
+      return false;
+    }
+    target.copy(s);
+    return true;
+  };
+
+  /** Native Java Object representation of the value */
+  public Object objectVal(int doc) {
+    // most DocValues are functions, so by default return a Float()
+    return floatVal(doc);
+  }
+
+  /** Returns true if there is a value for this document */
+  public boolean exists(int doc) {
+    return true;
+  }
+
   /**
    * @param doc The doc to retrieve to sort ordinal for
    * @return the sort ordinal for the specified doc

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DoubleConstValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DoubleConstValueSource.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DoubleConstValueSource.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DoubleConstValueSource.java Fri Apr 15 21:13:42 2011
@@ -40,7 +40,7 @@ public class DoubleConstValueSource exte
 
   @Override
   public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
-    return new DocValues() {
+    return new DoubleDocValues(this) {
       @Override
       public float floatVal(int doc) {
         return fv;
@@ -67,6 +67,11 @@ public class DoubleConstValueSource exte
       }
 
       @Override
+      public Object objectVal(int doc) {
+        return constant;
+      }
+
+      @Override
       public String toString(int doc) {
         return description();
       }

Added: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DoubleDocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DoubleDocValues.java?rev=1092812&view=auto
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DoubleDocValues.java (added)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DoubleDocValues.java Fri Apr 15 21:13:42 2011
@@ -0,0 +1,74 @@
+package org.apache.solr.search.function;
+
+import org.apache.solr.search.MutableValue;
+import org.apache.solr.search.MutableValueDouble;
+
+public abstract class DoubleDocValues extends DocValues {
+  protected final ValueSource vs;
+
+  public DoubleDocValues(ValueSource vs) {
+    this.vs = vs;
+  }
+
+  @Override
+  public byte byteVal(int doc) {
+    return (byte)doubleVal(doc);
+  }
+
+  @Override
+  public short shortVal(int doc) {
+    return (short)doubleVal(doc);
+  }
+
+  @Override
+  public float floatVal(int doc) {
+    return (float)doubleVal(doc);
+  }
+
+  @Override
+  public int intVal(int doc) {
+    return (int)doubleVal(doc);
+  }
+
+  @Override
+  public long longVal(int doc) {
+    return (long)doubleVal(doc);
+  }
+
+  @Override
+  public abstract double doubleVal(int doc);
+
+  @Override
+  public String strVal(int doc) {
+    return Double.toString(doubleVal(doc));
+  }
+
+  @Override
+  public Object objectVal(int doc) {
+    return exists(doc) ? doubleVal(doc) : null;
+  }
+
+  @Override
+  public String toString(int doc) {
+    return vs.description() + '=' + strVal(doc);
+  }
+
+  @Override
+  public ValueFiller getValueFiller() {
+    return new ValueFiller() {
+      private final MutableValueDouble mval = new MutableValueDouble();
+
+      @Override
+      public MutableValue getValue() {
+        return mval;
+      }
+
+      @Override
+      public void fillValue(int doc) {
+        mval.value = doubleVal(doc);
+        mval.exists = exists(doc);
+      }
+    };
+  }
+
+}

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DoubleFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DoubleFieldSource.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DoubleFieldSource.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DoubleFieldSource.java Fri Apr 15 21:13:42 2011
@@ -51,7 +51,7 @@ public class DoubleFieldSource extends N
   public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
     final DoubleValues vals = cache.getDoubles(readerContext.reader, field, creator);
     final double[] arr = vals.values;
-	final Bits valid = vals.valid;
+    final Bits valid = vals.valid;
     
     return new DocValues() {
       @Override
@@ -80,6 +80,11 @@ public class DoubleFieldSource extends N
       }
 
       @Override
+      public Object objectVal(int doc) {
+        return valid.get(doc) ? arr[doc] : null;
+      }
+
+      @Override
       public String toString(int doc) {
         return description() + '=' + doubleVal(doc);
       }

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DualFloatFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DualFloatFunction.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DualFloatFunction.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/DualFloatFunction.java Fri Apr 15 21:13:42 2011
@@ -48,28 +48,12 @@ public abstract class DualFloatFunction 
   public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
     final DocValues aVals =  a.getValues(context, readerContext);
     final DocValues bVals =  b.getValues(context, readerContext);
-    return new DocValues() {
+    return new FloatDocValues(this) {
       @Override
       public float floatVal(int doc) {
 	return func(doc, aVals, bVals);
       }
       @Override
-      public int intVal(int doc) {
-        return (int)floatVal(doc);
-      }
-      @Override
-      public long longVal(int doc) {
-        return (long)floatVal(doc);
-      }
-      @Override
-      public double doubleVal(int doc) {
-        return floatVal(doc);
-      }
-      @Override
-      public String strVal(int doc) {
-        return Float.toString(floatVal(doc));
-      }
-      @Override
       public String toString(int doc) {
 	return name() + '(' + aVals.toString(doc) + ',' + bVals.toString(doc) + ')';
       }

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/FileFloatSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/FileFloatSource.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/FileFloatSource.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/FileFloatSource.java Fri Apr 15 21:13:42 2011
@@ -65,35 +65,15 @@ public class FileFloatSource extends Val
     final int off = offset;
 
     final float[] arr = getCachedFloats(topLevelContext.reader);
-    return new DocValues() {
+    return new FloatDocValues(this) {
       @Override
       public float floatVal(int doc) {
         return arr[doc + off];
       }
 
       @Override
-      public int intVal(int doc) {
-        return (int)arr[doc + off];
-      }
-
-      @Override
-      public long longVal(int doc) {
-        return (long)arr[doc + off];
-      }
-
-      @Override
-      public double doubleVal(int doc) {
-        return (double)arr[doc + off];
-      }
-
-      @Override
-      public String strVal(int doc) {
-        return Float.toString(arr[doc + off]);
-      }
-
-      @Override
-      public String toString(int doc) {
-        return description() + '=' + floatVal(doc);
+      public Object objectVal(int doc) {
+        return floatVal(doc);   // TODO: keep track of missing values
       }
     };
   }

Added: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/FloatDocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/FloatDocValues.java?rev=1092812&view=auto
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/FloatDocValues.java (added)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/FloatDocValues.java Fri Apr 15 21:13:42 2011
@@ -0,0 +1,73 @@
+package org.apache.solr.search.function;
+
+import org.apache.solr.search.MutableValue;
+import org.apache.solr.search.MutableValueFloat;
+
+public abstract class FloatDocValues extends DocValues {
+  protected final ValueSource vs;
+
+  public FloatDocValues(ValueSource vs) {
+    this.vs = vs;
+  }
+
+  @Override
+  public byte byteVal(int doc) {
+    return (byte)floatVal(doc);
+  }
+
+  @Override
+  public short shortVal(int doc) {
+    return (short)floatVal(doc);
+  }
+
+  @Override
+  public abstract float floatVal(int doc);
+
+  @Override
+  public int intVal(int doc) {
+    return (int)floatVal(doc);
+  }
+
+  @Override
+  public long longVal(int doc) {
+    return (long)floatVal(doc);
+  }
+
+  @Override
+  public double doubleVal(int doc) {
+    return (double)floatVal(doc);
+  }
+
+  @Override
+  public String strVal(int doc) {
+    return Float.toString(floatVal(doc));
+  }
+
+  @Override
+  public Object objectVal(int doc) {
+    return exists(doc) ? floatVal(doc) : null;
+  }
+
+  @Override
+  public String toString(int doc) {
+    return vs.description() + '=' + strVal(doc);
+  }
+
+  @Override
+  public ValueFiller getValueFiller() {
+    return new ValueFiller() {
+      private final MutableValueFloat mval = new MutableValueFloat();
+
+      @Override
+      public MutableValue getValue() {
+        return mval;
+      }
+
+      @Override
+      public void fillValue(int doc) {
+        mval.value = floatVal(doc);
+        mval.exists = exists(doc);
+      }
+    };
+  }
+}

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/FloatFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/FloatFieldSource.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/FloatFieldSource.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/FloatFieldSource.java Fri Apr 15 21:13:42 2011
@@ -50,37 +50,22 @@ public class FloatFieldSource extends Nu
   public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
     final FloatValues vals = cache.getFloats(readerContext.reader, field, creator);
     final float[] arr = vals.values;
-	final Bits valid = vals.valid;
+    final Bits valid = vals.valid;
     
-    return new DocValues() {
+    return new FloatDocValues(this) {
       @Override
       public float floatVal(int doc) {
         return arr[doc];
       }
 
       @Override
-      public int intVal(int doc) {
-        return (int)arr[doc];
+      public Object objectVal(int doc) {
+        return valid.get(doc) ? arr[doc] : null;
       }
 
       @Override
-      public long longVal(int doc) {
-        return (long)arr[doc];
-      }
-
-      @Override
-      public double doubleVal(int doc) {
-        return (double)arr[doc];
-      }
-
-      @Override
-      public String strVal(int doc) {
-        return Float.toString(arr[doc]);
-      }
-
-      @Override
-      public String toString(int doc) {
-        return description() + '=' + floatVal(doc);
+      public boolean exists(int doc) {
+        return valid.get(doc);
       }
 
       @Override

Added: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/IntDocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/IntDocValues.java?rev=1092812&view=auto
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/IntDocValues.java (added)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/IntDocValues.java Fri Apr 15 21:13:42 2011
@@ -0,0 +1,73 @@
+package org.apache.solr.search.function;
+
+import org.apache.solr.search.MutableValue;
+import org.apache.solr.search.MutableValueInt;
+
+public abstract class IntDocValues extends DocValues {
+  protected final ValueSource vs;
+
+  public IntDocValues(ValueSource vs) {
+    this.vs = vs;
+  }
+
+  @Override
+  public byte byteVal(int doc) {
+    return (byte)intVal(doc);
+  }
+
+  @Override
+  public short shortVal(int doc) {
+    return (short)intVal(doc);
+  }
+
+  @Override
+  public float floatVal(int doc) {
+    return (float)intVal(doc);
+  }
+
+  @Override
+  public abstract int intVal(int doc);
+
+  @Override
+  public long longVal(int doc) {
+    return (long)intVal(doc);
+  }
+
+  @Override
+  public double doubleVal(int doc) {
+    return (double)intVal(doc);
+  }
+
+  @Override
+  public String strVal(int doc) {
+    return Integer.toString(intVal(doc));
+  }
+
+  @Override
+  public Object objectVal(int doc) {
+    return exists(doc) ? intVal(doc) : null;
+  }
+
+  @Override
+  public String toString(int doc) {
+    return vs.description() + '=' + strVal(doc);
+  }
+
+  @Override
+  public ValueFiller getValueFiller() {
+    return new ValueFiller() {
+      private final MutableValueInt mval = new MutableValueInt();
+
+      @Override
+      public MutableValue getValue() {
+        return mval;
+      }
+
+      @Override
+      public void fillValue(int doc) {
+        mval.value = intVal(doc);
+        mval.exists = exists(doc);
+      }
+    };
+  }
+}

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/IntFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/IntFieldSource.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/IntFieldSource.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/IntFieldSource.java Fri Apr 15 21:13:42 2011
@@ -51,9 +51,9 @@ public class IntFieldSource extends Nume
   public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
     final IntValues vals = cache.getInts(readerContext.reader, field, creator);
     final int[] arr = vals.values;
-	final Bits valid = vals.valid;
+    final Bits valid = vals.valid;
     
-    return new DocValues() {
+    return new IntDocValues(this) {
       final MutableValueInt val = new MutableValueInt();
       
       @Override
@@ -82,6 +82,16 @@ public class IntFieldSource extends Nume
       }
 
       @Override
+      public Object objectVal(int doc) {
+        return valid.get(doc) ? arr[doc] : null;
+      }
+
+      @Override
+      public boolean exists(int doc) {
+        return valid.get(doc);
+      }
+
+      @Override
       public String toString(int doc) {
         return description() + '=' + intVal(doc);
       }

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/JoinDocFreqValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/JoinDocFreqValueSource.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/JoinDocFreqValueSource.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/JoinDocFreqValueSource.java Fri Apr 15 21:13:42 2011
@@ -54,7 +54,7 @@ public class JoinDocFreqValueSource exte
     final DocTerms terms = cache.getTerms(readerContext.reader, field, true );
     final IndexReader top = ReaderUtil.getTopLevelContext(readerContext).reader;
     
-    return new DocValues() {
+    return new IntDocValues(this) {
       BytesRef ref = new BytesRef();
 
       @Override
@@ -70,31 +70,6 @@ public class JoinDocFreqValueSource exte
           throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "caught exception in function "+description()+" : doc="+doc, e);
         }
       }
-
-      @Override
-      public float floatVal(int doc) {
-        return (float)intVal(doc);
-      }
-
-      @Override
-      public long longVal(int doc) {
-        return (long)intVal(doc);
-      }
-
-      @Override
-      public double doubleVal(int doc) {
-        return (double)intVal(doc);
-      }
-
-      @Override
-      public String strVal(int doc) {
-        return intVal(doc) + "";
-      }
-
-      @Override
-      public String toString(int doc) {
-        return description() + '=' + intVal(doc);
-      }
     };
   }
   

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/LinearFloatFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/LinearFloatFunction.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/LinearFloatFunction.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/LinearFloatFunction.java Fri Apr 15 21:13:42 2011
@@ -50,28 +50,12 @@ public class LinearFloatFunction extends
   @Override
   public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
     final DocValues vals =  source.getValues(context, readerContext);
-    return new DocValues() {
+    return new FloatDocValues(this) {
       @Override
       public float floatVal(int doc) {
         return vals.floatVal(doc) * slope + intercept;
       }
       @Override
-      public int intVal(int doc) {
-        return (int)floatVal(doc);
-      }
-      @Override
-      public long longVal(int doc) {
-        return (long)floatVal(doc);
-      }
-      @Override
-      public double doubleVal(int doc) {
-        return (double)floatVal(doc);
-      }
-      @Override
-      public String strVal(int doc) {
-        return Float.toString(floatVal(doc));
-      }
-      @Override
       public String toString(int doc) {
         return slope + "*float(" + vals.toString(doc) + ")+" + intercept;
       }

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/LiteralValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/LiteralValueSource.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/LiteralValueSource.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/LiteralValueSource.java Fri Apr 15 21:13:42 2011
@@ -17,19 +17,23 @@ package org.apache.solr.search.function;
  */
 
 import org.apache.lucene.index.IndexReader.AtomicReaderContext;
+import org.apache.lucene.util.BytesRef;
 
 import java.util.Map;
 import java.io.IOException;
 
 
 /**
- * Pass a the field value through as a String, no matter the type
+ * Pass a the field value through as a String, no matter the type // Q: doesn't this mean it's a "string"?
  *
  **/
 public class LiteralValueSource extends ValueSource {
   protected final String string;
+  protected final BytesRef bytesRef;
+
   public LiteralValueSource(String string) {
     this.string = string;
+    this.bytesRef = new BytesRef(string);
   }
 
   /** returns the literal value */
@@ -40,13 +44,19 @@ public class LiteralValueSource extends 
   @Override
   public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
 
-    return new DocValues() {
+    return new StrDocValues(this) {
       @Override
       public String strVal(int doc) {
         return string;
       }
 
       @Override
+      public boolean bytesVal(int doc, BytesRef target) {
+        target.copy(bytesRef);
+        return true;
+      }
+
+      @Override
       public String toString(int doc) {
         return string;
       }

Added: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/LongDocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/LongDocValues.java?rev=1092812&view=auto
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/LongDocValues.java (added)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/LongDocValues.java Fri Apr 15 21:13:42 2011
@@ -0,0 +1,73 @@
+package org.apache.solr.search.function;
+
+import org.apache.solr.search.MutableValue;
+import org.apache.solr.search.MutableValueLong;
+
+public abstract class LongDocValues extends DocValues {
+  protected final ValueSource vs;
+
+  public LongDocValues(ValueSource vs) {
+    this.vs = vs;
+  }
+
+  @Override
+  public byte byteVal(int doc) {
+    return (byte)longVal(doc);
+  }
+
+  @Override
+  public short shortVal(int doc) {
+    return (short)longVal(doc);
+  }
+
+  @Override
+  public float floatVal(int doc) {
+    return (float)longVal(doc);
+  }
+
+  @Override
+  public int intVal(int doc) {
+    return (int)longVal(doc);
+  }
+
+  @Override
+  public abstract long longVal(int doc);
+
+  @Override
+  public double doubleVal(int doc) {
+    return (double)longVal(doc);
+  }
+
+  @Override
+  public String strVal(int doc) {
+    return Long.toString(longVal(doc));
+  }
+
+  @Override
+  public Object objectVal(int doc) {
+    return exists(doc) ? longVal(doc) : null;
+  }
+
+  @Override
+  public String toString(int doc) {
+    return vs.description() + '=' + strVal(doc);
+  }
+
+  @Override
+  public ValueFiller getValueFiller() {
+    return new ValueFiller() {
+      private final MutableValueLong mval = new MutableValueLong();
+
+      @Override
+      public MutableValue getValue() {
+        return mval;
+      }
+
+      @Override
+      public void fillValue(int doc) {
+        mval.value = longVal(doc);
+        mval.exists = exists(doc);
+      }
+    };
+  }
+}

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/LongFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/LongFieldSource.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/LongFieldSource.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/LongFieldSource.java Fri Apr 15 21:13:42 2011
@@ -52,41 +52,30 @@ public class LongFieldSource extends Num
     return Long.parseLong(extVal);
   }
 
+  public Object longToObject(long val) {
+    return val;
+  }
+
   @Override
   public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
     final LongValues vals = cache.getLongs(readerContext.reader, field, creator);
     final long[] arr = vals.values;
-	final Bits valid = vals.valid;
+    final Bits valid = vals.valid;
     
-    return new DocValues() {
-      @Override
-      public float floatVal(int doc) {
-        return (float) arr[doc];
-      }
-
-      @Override
-      public int intVal(int doc) {
-        return (int) arr[doc];
-      }
-
+    return new LongDocValues(this) {
       @Override
       public long longVal(int doc) {
         return arr[doc];
       }
 
       @Override
-      public double doubleVal(int doc) {
-        return arr[doc];
+      public boolean exists(int doc) {
+        return valid.get(doc);
       }
 
       @Override
-      public String strVal(int doc) {
-        return Long.toString(arr[doc]);
-      }
-
-      @Override
-      public String toString(int doc) {
-        return description() + '=' + longVal(doc);
+      public Object objectVal(int doc) {
+        return valid.get(doc) ? longToObject(arr[doc]) : null;
       }
 
       @Override
@@ -142,8 +131,6 @@ public class LongFieldSource extends Num
         };
       }
 
-
-
     };
   }
 

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/MultiFloatFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/MultiFloatFunction.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/MultiFloatFunction.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/MultiFloatFunction.java Fri Apr 15 21:13:42 2011
@@ -62,28 +62,12 @@ public abstract class MultiFloatFunction
       valsArr[i] = sources[i].getValues(context, readerContext);
     }
 
-    return new DocValues() {
+    return new FloatDocValues(this) {
       @Override
       public float floatVal(int doc) {
         return func(doc, valsArr);
       }
-      @Override
-      public int intVal(int doc) {
-        return (int)floatVal(doc);
-      }
-      @Override
-      public long longVal(int doc) {
-        return (long)floatVal(doc);
-      }
-      @Override
-      public double doubleVal(int doc) {
-        return (double)floatVal(doc);
-      }
-      @Override
-      public String strVal(int doc) {
-        return Float.toString(floatVal(doc));
-      }
-      @Override
+       @Override
       public String toString(int doc) {
         StringBuilder sb = new StringBuilder();
         sb.append(name()).append('(');

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/OrdFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/OrdFieldSource.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/OrdFieldSource.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/OrdFieldSource.java Fri Apr 15 21:13:42 2011
@@ -63,53 +63,29 @@ public class OrdFieldSource extends Valu
     final int off = readerContext.docBase;
     final IndexReader topReader = ReaderUtil.getTopLevelContext(readerContext).reader;
     final FieldCache.DocTermsIndex sindex = FieldCache.DEFAULT.getTermsIndex(topReader, field);
-    return new DocValues() {
+    return new IntDocValues(this) {
       protected String toTerm(String readableValue) {
         return readableValue;
       }
-      
-      @Override
-      public float floatVal(int doc) {
-        return (float)sindex.getOrd(doc+off);
-      }
-
       @Override
       public int intVal(int doc) {
         return sindex.getOrd(doc+off);
       }
-
-      @Override
-      public long longVal(int doc) {
-        return (long)sindex.getOrd(doc+off);
-      }
-
-      @Override
-      public double doubleVal(int doc) {
-        return (double)sindex.getOrd(doc+off);
-      }
-
       @Override
       public int ordVal(int doc) {
         return sindex.getOrd(doc+off);
       }
-
       @Override
       public int numOrd() {
         return sindex.numOrd();
       }
 
       @Override
-      public String strVal(int doc) {
-        // the string value of the ordinal, not the string itself
-        return Integer.toString(sindex.getOrd(doc+off));
+      public boolean exists(int doc) {
+        return sindex.getOrd(doc+off) != 0;
       }
 
       @Override
-      public String toString(int doc) {
-        return description() + '=' + intVal(doc);
-      }
-
-            @Override
       public ValueFiller getValueFiller() {
         return new ValueFiller() {
           private final MutableValueInt mval = new MutableValueInt();

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/QueryValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/QueryValueSource.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/QueryValueSource.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/QueryValueSource.java Fri Apr 15 21:13:42 2011
@@ -23,6 +23,8 @@ import org.apache.lucene.search.*;
 import org.apache.lucene.search.Weight.ScorerContext;
 import org.apache.lucene.util.ReaderUtil;
 import org.apache.solr.common.SolrException;
+import org.apache.solr.search.MutableValue;
+import org.apache.solr.search.MutableValueFloat;
 
 import java.io.IOException;
 import java.util.Map;
@@ -49,7 +51,7 @@ public class QueryValueSource extends Va
 
   @Override
   public DocValues getValues(Map fcontext, AtomicReaderContext readerContext) throws IOException {
-    return new QueryDocValues(readerContext, q, defVal, fcontext);
+    return new QueryDocValues(this, readerContext, fcontext);
   }
 
   @Override
@@ -72,31 +74,31 @@ public class QueryValueSource extends Va
 }
 
 
-class QueryDocValues extends DocValues {
-  final Query q;
-//  final IndexReader reader;
+class QueryDocValues extends FloatDocValues {
   final AtomicReaderContext readerContext;
   final Weight weight;
   final float defVal;
   final Map fcontext;
+  final Query q;
 
   Scorer scorer;
   int scorerDoc; // the document the scorer is on
+  boolean noMatches=false;
 
   // the last document requested... start off with high value
   // to trigger a scorer reset on first access.
   int lastDocRequested=Integer.MAX_VALUE;
   
 
-  public QueryDocValues(AtomicReaderContext readerContext, Query q, float defVal, Map fcontext) throws IOException {
-    IndexReader reader = readerContext.reader;
+  public QueryDocValues(QueryValueSource vs, AtomicReaderContext readerContext, Map fcontext) throws IOException {
+    super(vs);
+
     this.readerContext = readerContext;
-    this.q = q;
-    this.defVal = defVal;
+    this.defVal = vs.defVal;
+    this.q = vs.q;
     this.fcontext = fcontext;
 
     Weight w = fcontext==null ? null : (Weight)fcontext.get(q);
-    // TODO: sort by function doesn't weight (SOLR-1297 is open because of this bug)... so weightSearcher will currently be null
     if (w == null) {
       IndexSearcher weightSearcher;
       if(fcontext == null) {
@@ -116,8 +118,12 @@ class QueryDocValues extends DocValues {
   public float floatVal(int doc) {
     try {
       if (doc < lastDocRequested) {
+        if (noMatches) return defVal;
         scorer = weight.scorer(readerContext, ScorerContext.def());
-        if (scorer==null) return defVal;
+        if (scorer==null) {
+          noMatches = true;
+          return defVal;
+        }
         scorerDoc = -1;
       }
       lastDocRequested = doc;
@@ -137,24 +143,104 @@ class QueryDocValues extends DocValues {
     } catch (IOException e) {
       throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "caught exception in QueryDocVals("+q+") doc="+doc, e);
     }
-  }  
-
-  @Override
-  public int intVal(int doc) {
-    return (int)floatVal(doc);
-  }
-  @Override
-  public long longVal(int doc) {
-    return (long)floatVal(doc);
   }
+
   @Override
-  public double doubleVal(int doc) {
-    return (double)floatVal(doc);
+  public boolean exists(int doc) {
+    try {
+      if (doc < lastDocRequested) {
+        if (noMatches) return false;
+        scorer = weight.scorer(readerContext, ScorerContext.def());
+        scorerDoc = -1;
+        if (scorer==null) {
+          noMatches = true;
+          return false;
+        }
+      }
+      lastDocRequested = doc;
+
+      if (scorerDoc < doc) {
+        scorerDoc = scorer.advance(doc);
+      }
+
+      if (scorerDoc > doc) {
+        // query doesn't match this document... either because we hit the
+        // end, or because the next doc is after this doc.
+        return false;
+      }
+
+      // a match!
+      return true;
+    } catch (IOException e) {
+      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "caught exception in QueryDocVals("+q+") doc="+doc, e);
+    }
   }
-  @Override
-  public String strVal(int doc) {
-    return Float.toString(floatVal(doc));
+
+   @Override
+  public Object objectVal(int doc) {
+     try {
+       return exists(doc) ? scorer.score() : null;
+     } catch (IOException e) {
+       throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "caught exception in QueryDocVals("+q+") doc="+doc, e);
+     }
+   }
+
+  @Override
+  public ValueFiller getValueFiller() {
+    //
+    // TODO: if we want to support more than one value-filler or a value-filler in conjunction with
+    // the DocValues, then members like "scorer" should be per ValueFiller instance.
+    // Or we can say that the user should just instantiate multiple DocValues.
+    //
+    return new ValueFiller() {
+      private final MutableValueFloat mval = new MutableValueFloat();
+
+      @Override
+      public MutableValue getValue() {
+        return mval;
+      }
+
+      @Override
+      public void fillValue(int doc) {
+        try {
+          if (noMatches) {
+            mval.value = defVal;
+            mval.exists = false;
+            return;
+          }
+          scorer = weight.scorer(readerContext, ScorerContext.def());
+          scorerDoc = -1;
+          if (scorer==null) {
+            noMatches = true;
+            mval.value = defVal;
+            mval.exists = false;
+            return;
+          }
+          lastDocRequested = doc;
+
+          if (scorerDoc < doc) {
+            scorerDoc = scorer.advance(doc);
+          }
+
+          if (scorerDoc > doc) {
+            // query doesn't match this document... either because we hit the
+            // end, or because the next doc is after this doc.
+            mval.value = defVal;
+            mval.exists = false;
+            return;
+          }
+
+          // a match!
+          mval.value = scorer.score();
+          mval.exists = true;
+          return;
+        } catch (IOException e) {
+          throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "caught exception in QueryDocVals("+q+") doc="+doc, e);
+        }
+      }
+    };
   }
+
   @Override
   public String toString(int doc) {
     return "query(" + q + ",def=" + defVal + ")=" + floatVal(doc);

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/RangeMapFloatFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/RangeMapFloatFunction.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/RangeMapFloatFunction.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/RangeMapFloatFunction.java Fri Apr 15 21:13:42 2011
@@ -54,29 +54,13 @@ public class RangeMapFloatFunction exten
   @Override
   public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
     final DocValues vals =  source.getValues(context, readerContext);
-    return new DocValues() {
+    return new FloatDocValues(this) {
       @Override
       public float floatVal(int doc) {
         float val = vals.floatVal(doc);
         return (val>=min && val<=max) ? target : (defaultVal == null ? val : defaultVal);
       }
       @Override
-      public int intVal(int doc) {
-        return (int)floatVal(doc);
-      }
-      @Override
-      public long longVal(int doc) {
-        return (long)floatVal(doc);
-      }
-      @Override
-      public double doubleVal(int doc) {
-        return (double)floatVal(doc);
-      }
-      @Override
-      public String strVal(int doc) {
-        return Float.toString(floatVal(doc));
-      }
-      @Override
       public String toString(int doc) {
         return "map(" + vals.toString(doc) + ",min=" + min + ",max=" + max + ",target=" + target + ")";
       }

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ReciprocalFloatFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ReciprocalFloatFunction.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ReciprocalFloatFunction.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ReciprocalFloatFunction.java Fri Apr 15 21:13:42 2011
@@ -60,28 +60,12 @@ public class ReciprocalFloatFunction ext
   @Override
   public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
     final DocValues vals = source.getValues(context, readerContext);
-    return new DocValues() {
+    return new FloatDocValues(this) {
       @Override
       public float floatVal(int doc) {
         return a/(m*vals.floatVal(doc) + b);
       }
       @Override
-      public int intVal(int doc) {
-        return (int)floatVal(doc);
-      }
-      @Override
-      public long longVal(int doc) {
-        return (long)floatVal(doc);
-      }
-      @Override
-      public double doubleVal(int doc) {
-        return (double)floatVal(doc);
-      }
-      @Override
-      public String strVal(int doc) {
-        return Float.toString(floatVal(doc));
-      }
-      @Override
       public String toString(int doc) {
         return Float.toString(a) + "/("
                 + m + "*float(" + vals.toString(doc) + ')'

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ReverseOrdFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ReverseOrdFieldSource.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ReverseOrdFieldSource.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ReverseOrdFieldSource.java Fri Apr 15 21:13:42 2011
@@ -66,47 +66,11 @@ public class ReverseOrdFieldSource exten
     final FieldCache.DocTermsIndex sindex = FieldCache.DEFAULT.getTermsIndex(topReader, field);
     final int end = sindex.numOrd();
 
-    return new DocValues() {
-      @Override
-      public float floatVal(int doc) {
-        return (float)(end - sindex.getOrd(doc+off));
-      }
-
-      @Override
+    return new IntDocValues(this) {
+     @Override
       public int intVal(int doc) {
         return (end - sindex.getOrd(doc+off));
       }
-
-      @Override
-      public long longVal(int doc) {
-        return (long)(end - sindex.getOrd(doc+off));
-      }
-
-      @Override
-      public int ordVal(int doc) {
-        return (end - sindex.getOrd(doc+off));
-      }
-
-      @Override
-      public int numOrd() {
-        return end;
-      }
-
-      @Override
-      public double doubleVal(int doc) {
-        return (double)(end - sindex.getOrd(doc+off));
-      }
-
-      @Override
-      public String strVal(int doc) {
-        // the string value of the ordinal, not the string itself
-        return Integer.toString((end - sindex.getOrd(doc+off)));
-      }
-
-      @Override
-      public String toString(int doc) {
-        return description() + '=' + strVal(doc);
-      }
     };
   }
 

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ScaleFloatFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ScaleFloatFunction.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ScaleFloatFunction.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/ScaleFloatFunction.java Fri Apr 15 21:13:42 2011
@@ -108,28 +108,12 @@ public class ScaleFloatFunction extends 
 
     final DocValues vals =  source.getValues(context, readerContext);
 
-    return new DocValues() {
+    return new FloatDocValues(this) {
       @Override
       public float floatVal(int doc) {
 	return (vals.floatVal(doc) - minSource) * scale + min;
       }
       @Override
-      public int intVal(int doc) {
-        return (int)floatVal(doc);
-      }
-      @Override
-      public long longVal(int doc) {
-        return (long)floatVal(doc);
-      }
-      @Override
-      public double doubleVal(int doc) {
-        return (double)floatVal(doc);
-      }
-      @Override
-      public String strVal(int doc) {
-        return Float.toString(floatVal(doc));
-      }
-      @Override
       public String toString(int doc) {
 	return "scale(" + vals.toString(doc) + ",toMin=" + min + ",toMax=" + max
                 + ",fromMin=" + minSource

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/SimpleFloatFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/SimpleFloatFunction.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/SimpleFloatFunction.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/SimpleFloatFunction.java Fri Apr 15 21:13:42 2011
@@ -34,28 +34,12 @@ import java.util.Map;
   @Override
   public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
     final DocValues vals =  source.getValues(context, readerContext);
-    return new DocValues() {
+    return new FloatDocValues(this) {
       @Override
       public float floatVal(int doc) {
 	return func(doc, vals);
       }
       @Override
-      public int intVal(int doc) {
-        return (int)floatVal(doc);
-      }
-      @Override
-      public long longVal(int doc) {
-        return (long)floatVal(doc);
-      }
-      @Override
-      public double doubleVal(int doc) {
-        return (double)floatVal(doc);
-      }
-      @Override
-      public String strVal(int doc) {
-        return Float.toString(floatVal(doc));
-      }
-      @Override
       public String toString(int doc) {
 	return name() + '(' + vals.toString(doc) + ')';
       }

Added: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/StrDocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/StrDocValues.java?rev=1092812&view=auto
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/StrDocValues.java (added)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/StrDocValues.java Fri Apr 15 21:13:42 2011
@@ -0,0 +1,45 @@
+package org.apache.solr.search.function;
+
+import org.apache.lucene.util.BytesRef;
+import org.apache.noggit.CharArr;
+import org.apache.solr.search.MutableValue;
+import org.apache.solr.search.MutableValueFloat;
+import org.apache.solr.search.MutableValueStr;
+
+public abstract class StrDocValues extends DocValues {
+  protected final ValueSource vs;
+
+  public StrDocValues(ValueSource vs) {
+    this.vs = vs;
+  }
+
+  @Override
+  public abstract String strVal(int doc);
+
+  @Override
+  public Object objectVal(int doc) {
+    return exists(doc) ? strVal(doc) : null;
+  }
+
+  @Override
+  public String toString(int doc) {
+    return vs.description() + "='" + strVal(doc) + "'";
+  }
+
+  @Override
+  public ValueFiller getValueFiller() {
+    return new ValueFiller() {
+      private final MutableValueStr mval = new MutableValueStr();
+
+      @Override
+      public MutableValue getValue() {
+        return mval;
+      }
+
+      @Override
+      public void fillValue(int doc) {
+        mval.exists = bytesVal(doc, mval.value);
+      }
+    };
+  }
+}

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/StringIndexDocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/StringIndexDocValues.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/StringIndexDocValues.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/StringIndexDocValues.java Fri Apr 15 21:13:42 2011
@@ -21,8 +21,10 @@ import org.apache.lucene.search.FieldCac
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.lucene.util.BytesRef;
+import org.apache.noggit.CharArr;
 import org.apache.solr.search.MutableValue;
 import org.apache.solr.search.MutableValueStr;
+import org.apache.solr.util.ByteUtils;
 
 import java.io.IOException;
 
@@ -30,64 +32,97 @@ import java.io.IOException;
  *  Serves as base class for DocValues based on StringIndex 
  **/
 public abstract class StringIndexDocValues extends DocValues {
-    protected final FieldCache.DocTermsIndex termsIndex;
-    protected final ValueSource vs;
-    protected final MutableValueStr val = new MutableValueStr();
-
-    public StringIndexDocValues(ValueSource vs, AtomicReaderContext context, String field) throws IOException {
-      try {
-        termsIndex = FieldCache.DEFAULT.getTermsIndex(context.reader, field);
-      } catch (RuntimeException e) {
-        throw new StringIndexException(field, e);
-      }
-      this.vs = vs;
+  protected final FieldCache.DocTermsIndex termsIndex;
+  protected final ValueSource vs;
+  protected final MutableValueStr val = new MutableValueStr();
+  protected final BytesRef spare = new BytesRef();
+  protected final CharArr spareChars = new CharArr();
+
+  public StringIndexDocValues(ValueSource vs, AtomicReaderContext context, String field) throws IOException {
+    try {
+      termsIndex = FieldCache.DEFAULT.getTermsIndex(context.reader, field);
+    } catch (RuntimeException e) {
+      throw new StringIndexException(field, e);
     }
+    this.vs = vs;
+  }
+
+  public FieldCache.DocTermsIndex getDocTermsIndex() {
+    return termsIndex;
+  }
+
+  protected abstract String toTerm(String readableValue);
+
+  @Override
+  public boolean exists(int doc) {
+    return termsIndex.getOrd(doc) != 0;
+  }
+
 
-    public FieldCache.DocTermsIndex getDocTermsIndex() {
-      return termsIndex;
+  @Override
+  public boolean bytesVal(int doc, BytesRef target) {
+    int ord=termsIndex.getOrd(doc);
+    if (ord==0) {
+      target.length = 0;
+      return false;
     }
-  
-    protected abstract String toTerm(String readableValue);
+    termsIndex.lookup(ord, target);
+    return true;
+  }
+
+  @Override
+  public String strVal(int doc) {
+    int ord=termsIndex.getOrd(doc);
+    if (ord==0) return null;
+    termsIndex.lookup(ord, spare);
+    spareChars.reset();
+    ByteUtils.UTF8toUTF16(spare, spareChars);
+    return spareChars.toString();
+  }
 
-    @Override
-    public ValueSourceScorer getRangeScorer(IndexReader reader, String lowerVal, String upperVal, boolean includeLower, boolean includeUpper) {
-      // TODO: are lowerVal and upperVal in indexed form or not?
-      lowerVal = lowerVal == null ? null : toTerm(lowerVal);
-      upperVal = upperVal == null ? null : toTerm(upperVal);
-
-      final BytesRef spare = new BytesRef();
-
-      int lower = Integer.MIN_VALUE;
-      if (lowerVal != null) {
-        lower = termsIndex.binarySearchLookup(new BytesRef(lowerVal), spare);
-        if (lower < 0) {
-          lower = -lower-1;
-        } else if (!includeLower) {
-          lower++;
-        }
+
+  @Override
+  public abstract Object objectVal(int doc);  // force subclasses to override
+
+  @Override
+  public ValueSourceScorer getRangeScorer(IndexReader reader, String lowerVal, String upperVal, boolean includeLower, boolean includeUpper) {
+    // TODO: are lowerVal and upperVal in indexed form or not?
+    lowerVal = lowerVal == null ? null : toTerm(lowerVal);
+    upperVal = upperVal == null ? null : toTerm(upperVal);
+
+    final BytesRef spare = new BytesRef();
+
+    int lower = Integer.MIN_VALUE;
+    if (lowerVal != null) {
+      lower = termsIndex.binarySearchLookup(new BytesRef(lowerVal), spare);
+      if (lower < 0) {
+        lower = -lower-1;
+      } else if (!includeLower) {
+        lower++;
       }
-      
-      int upper = Integer.MAX_VALUE;
-      if (upperVal != null) {
-        upper = termsIndex.binarySearchLookup(new BytesRef(upperVal), spare);
-        if (upper < 0) {
-          upper = -upper-2;
-        } else if (!includeUpper) {
-          upper--;
-        }
+    }
+
+    int upper = Integer.MAX_VALUE;
+    if (upperVal != null) {
+      upper = termsIndex.binarySearchLookup(new BytesRef(upperVal), spare);
+      if (upper < 0) {
+        upper = -upper-2;
+      } else if (!includeUpper) {
+        upper--;
       }
+    }
 
-      final int ll = lower;
-      final int uu = upper;
+    final int ll = lower;
+    final int uu = upper;
 
-      return new ValueSourceScorer(reader, this) {
-        @Override
-        public boolean matchesValue(int doc) {
-          int ord = termsIndex.getOrd(doc);
-          return ord >= ll && ord <= uu;
-        }
-      };
-    }
+    return new ValueSourceScorer(reader, this) {
+      @Override
+      public boolean matchesValue(int doc) {
+        int ord = termsIndex.getOrd(doc);
+        return ord >= ll && ord <= uu;
+      }
+    };
+  }
 
   @Override
   public String toString(int doc) {
@@ -117,7 +152,7 @@ public abstract class StringIndexDocValu
     public StringIndexException(final String fieldName,
                                 final RuntimeException cause) {
       super("Can't initialize StringIndex to generate (function) " +
-            "DocValues for field: " + fieldName, cause);
+              "DocValues for field: " + fieldName, cause);
     }
   }
 

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/GeohashHaversineFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/GeohashHaversineFunction.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/GeohashHaversineFunction.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/GeohashHaversineFunction.java Fri Apr 15 21:13:42 2011
@@ -18,6 +18,7 @@ package org.apache.solr.search.function.
 
 
 import org.apache.lucene.spatial.DistanceUtils;
+import org.apache.solr.search.function.DoubleDocValues;
 import org.apache.solr.search.function.ValueSource;
 import org.apache.solr.search.function.DocValues;
 import org.apache.lucene.index.IndexReader.AtomicReaderContext;
@@ -58,32 +59,11 @@ public class GeohashHaversineFunction ex
     final DocValues gh1DV = geoHash1.getValues(context, readerContext);
     final DocValues gh2DV = geoHash2.getValues(context, readerContext);
 
-    return new DocValues() {
-      @Override
-      public float floatVal(int doc) {
-        return (float) doubleVal(doc);
-      }
-
-      @Override
-      public int intVal(int doc) {
-        return (int) doubleVal(doc);
-      }
-
-      @Override
-      public long longVal(int doc) {
-        return (long) doubleVal(doc);
-      }
-
+    return new DoubleDocValues(this) {
       @Override
       public double doubleVal(int doc) {
         return distance(doc, gh1DV, gh2DV);
       }
-
-      @Override
-      public String strVal(int doc) {
-        return Double.toString(doubleVal(doc));
-      }
-
       @Override
       public String toString(int doc) {
         StringBuilder sb = new StringBuilder();

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/HaversineConstFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/HaversineConstFunction.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/HaversineConstFunction.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/HaversineConstFunction.java Fri Apr 15 21:13:42 2011
@@ -198,22 +198,7 @@ public class HaversineConstFunction exte
     final double lonCenterRad = this.lonCenter * DistanceUtils.DEGREES_TO_RADIANS;
     final double latCenterRad_cos = this.latCenterRad_cos;
 
-    return new DocValues() {
-      @Override
-      public float floatVal(int doc) {
-        return (float) doubleVal(doc);
-      }
-
-      @Override
-      public int intVal(int doc) {
-        return (int) doubleVal(doc);
-      }
-
-      @Override
-      public long longVal(int doc) {
-        return (long) doubleVal(doc);
-      }
-
+    return new DoubleDocValues(this) {
       @Override
       public double doubleVal(int doc) {
         double latRad = latVals.doubleVal(doc) * DistanceUtils.DEGREES_TO_RADIANS;
@@ -226,12 +211,6 @@ public class HaversineConstFunction exte
                 (latCenterRad_cos * Math.cos(latRad) * hsinY * hsinY);
         return (EARTH_MEAN_DIAMETER * Math.atan2(Math.sqrt(h), Math.sqrt(1 - h)));
       }
-
-      @Override
-      public String strVal(int doc) {
-        return Double.toString(doubleVal(doc));
-      }
-
       @Override
       public String toString(int doc) {
         return name() + '(' + latVals.toString(doc) + ',' + lonVals.toString(doc) + ',' + latCenter + ',' + lonCenter + ')';

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/HaversineFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/HaversineFunction.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/HaversineFunction.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/HaversineFunction.java Fri Apr 15 21:13:42 2011
@@ -20,6 +20,7 @@ import org.apache.lucene.index.IndexRead
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.spatial.DistanceUtils;
 import org.apache.solr.common.SolrException;
+import org.apache.solr.search.function.DoubleDocValues;
 import org.apache.solr.search.function.MultiValueSource;
 import org.apache.solr.search.function.DocValues;
 import org.apache.solr.search.function.ValueSource;
@@ -99,32 +100,11 @@ public class HaversineFunction extends V
     final DocValues vals1 = p1.getValues(context, readerContext);
 
     final DocValues vals2 = p2.getValues(context, readerContext);
-    return new DocValues() {
-      @Override
-      public float floatVal(int doc) {
-        return (float) doubleVal(doc);
-      }
-
-      @Override
-      public int intVal(int doc) {
-        return (int) doubleVal(doc);
-      }
-
-      @Override
-      public long longVal(int doc) {
-        return (long) doubleVal(doc);
-      }
-
+    return new DoubleDocValues(this) {
       @Override
       public double doubleVal(int doc) {
         return distance(doc, vals1, vals2);
       }
-
-      @Override
-      public String strVal(int doc) {
-        return Double.toString(doubleVal(doc));
-      }
-
       @Override
       public String toString(int doc) {
         StringBuilder sb = new StringBuilder();

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/StringDistanceFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/StringDistanceFunction.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/StringDistanceFunction.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/StringDistanceFunction.java Fri Apr 15 21:13:42 2011
@@ -20,6 +20,7 @@ package org.apache.solr.search.function.
 import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.lucene.search.spell.StringDistance;
 import org.apache.solr.search.function.DocValues;
+import org.apache.solr.search.function.FloatDocValues;
 import org.apache.solr.search.function.ValueSource;
 
 import java.io.IOException;
@@ -51,7 +52,7 @@ public class StringDistanceFunction exte
   public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
     final DocValues str1DV = str1.getValues(context, readerContext);
     final DocValues str2DV = str2.getValues(context, readerContext);
-    return new DocValues() {
+    return new FloatDocValues(this) {
 
       @Override
       public float floatVal(int doc) {
@@ -59,21 +60,6 @@ public class StringDistanceFunction exte
       }
 
       @Override
-      public int intVal(int doc) {
-        return (int) doubleVal(doc);
-      }
-
-      @Override
-      public long longVal(int doc) {
-        return (long) doubleVal(doc);
-      }
-
-      @Override
-      public double doubleVal(int doc) {
-        return (double) floatVal(doc);
-      }
-
-      @Override
       public String toString(int doc) {
         StringBuilder sb = new StringBuilder();
         sb.append("strdist").append('(');

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/VectorDistanceFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/VectorDistanceFunction.java?rev=1092812&r1=1092811&r2=1092812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/VectorDistanceFunction.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/function/distance/VectorDistanceFunction.java Fri Apr 15 21:13:42 2011
@@ -21,6 +21,7 @@ import org.apache.lucene.search.IndexSea
 import org.apache.lucene.spatial.DistanceUtils;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.search.function.DocValues;
+import org.apache.solr.search.function.DoubleDocValues;
 import org.apache.solr.search.function.MultiValueSource;
 import org.apache.solr.search.function.ValueSource;
 
@@ -85,31 +86,7 @@ public class VectorDistanceFunction exte
     final DocValues vals2 = source2.getValues(context, readerContext);
 
 
-    return new DocValues() {
-      @Override
-      public byte byteVal(int doc) {
-        return (byte) doubleVal(doc);
-      }
-
-      @Override
-      public short shortVal(int doc) {
-        return (short) doubleVal(doc);
-      }
-
-      @Override
-      public float floatVal(int doc) {
-        return (float) doubleVal(doc);
-      }
-
-      @Override
-      public int intVal(int doc) {
-        return (int) doubleVal(doc);
-      }
-
-      @Override
-      public long longVal(int doc) {
-        return (long) doubleVal(doc);
-      }
+    return new DoubleDocValues(this) {
 
       @Override
       public double doubleVal(int doc) {
@@ -117,11 +94,6 @@ public class VectorDistanceFunction exte
       }
 
       @Override
-      public String strVal(int doc) {
-        return Double.toString(doubleVal(doc));
-      }
-
-      @Override
       public String toString(int doc) {
         StringBuilder sb = new StringBuilder();
         sb.append(name()).append('(').append(power).append(',');



Mime
View raw message