risdenk commented on code in PR #840:
URL: https://github.com/apache/lucene/pull/840#discussion_r859076455


##########
lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DoubleFieldSource.java:
##########
@@ -52,55 +50,32 @@ public SortField getSortField(boolean reverse) {
   public FunctionValues getValues(Map<Object, Object> context, 
LeafReaderContext readerContext)
       throws IOException {
 
-    final NumericDocValues values = getNumericDocValues(context, 
readerContext);
+    final NumericDocValues arr = getNumericDocValues(context, readerContext);
 
     return new DoubleDocValues(this) {
       int lastDocID;
 
-      private double getValueForDoc(int doc) throws IOException {
-        if (doc < lastDocID) {
-          throw new IllegalArgumentException(
-              "docs were sent out-of-order: lastDocID=" + lastDocID + " vs 
docID=" + doc);
-        }
-        lastDocID = doc;
-        int curDocID = values.docID();
-        if (doc > curDocID) {
-          curDocID = values.advance(doc);
-        }
-        if (doc == curDocID) {
-          return Double.longBitsToDouble(values.longValue());
+      @Override
+      public double doubleVal(int doc) throws IOException {
+        if (exists(doc)) {
+          return Double.longBitsToDouble(arr.longValue());
         } else {
           return 0.0;
         }

Review Comment:
   A nice side effect of removing `getValueForDoc` and using `exists` is the 
logic is MUCH cleaner now. If value exists then go convert it - otherwise 
don't. It avoids the indirection from before. So I think this is using the API 
better than before.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to