tomglk commented on a change in pull request #123:
URL: https://github.com/apache/solr/pull/123#discussion_r631638003



##########
File path: 
solr/contrib/ltr/src/java/org/apache/solr/ltr/feature/FieldValueFeature.java
##########
@@ -146,5 +171,100 @@ public float getMaxScore(int upTo) throws IOException {
         return Float.POSITIVE_INFINITY;
       }
     }
+
+    /**
+     * A FeatureScorer that reads the docValues for a field
+     */
+    public class DocValuesFieldValueFeatureScorer extends 
FeatureWeight.FeatureScorer {
+      final LeafReaderContext context;
+      final DocIdSetIterator docValues;
+      final FieldType schemaFieldType;
+      DocValuesType docValuesType = DocValuesType.NONE;
+
+      public DocValuesFieldValueFeatureScorer(final FeatureWeight weight, 
final LeafReaderContext context,
+                                              final DocIdSetIterator itr, 
final SchemaField schemaField) {
+        super(weight, itr);
+        this.context = context;
+        schemaFieldType = schemaField.getType();
+
+        try {
+          FieldInfo fieldInfo = 
context.reader().getFieldInfos().fieldInfo(field);
+          // if fieldInfo is null, just use NONE-Type. This causes no 
problems, because we won't call score() anyway
+          docValuesType = fieldInfo != null ? fieldInfo.getDocValuesType() : 
DocValuesType.NONE;
+          switch (docValuesType) {
+            case NUMERIC:
+              docValues = DocValues.getNumeric(context.reader(), field);
+              break;
+            case SORTED:
+              docValues = DocValues.getSorted(context.reader(), field);
+              break;
+            case BINARY:
+            case SORTED_NUMERIC:
+            case SORTED_SET:
+            case NONE:
+            default:
+              docValues = null;
+          }
+        } catch (IOException e) {
+          throw new IllegalArgumentException("Could not read docValues for 
field " + field + " with docValuesType "
+              + docValuesType.name());
+        }
+      }
+
+      @Override
+      public float score() throws IOException {
+        if (docValues != null && docValues.advance(itr.docID()) < 
DocIdSetIterator.NO_MORE_DOCS) {
+          switch (docValuesType) {
+            case NUMERIC:
+              if (NumberType.FLOAT.equals(schemaFieldType.getNumberType())) {
+                // convert float value that was stored as long back to float
+                return Float.intBitsToFloat((int) ((NumericDocValues) 
docValues).longValue());
+              } else if 
(NumberType.DOUBLE.equals(schemaFieldType.getNumberType())) {

Review comment:
       Valid point. I applied your suggestion in commit 5bc995c.




-- 
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.

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



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

Reply via email to