tomglk commented on a change in pull request #123:
URL: https://github.com/apache/solr/pull/123#discussion_r639065556
##########
File path:
solr/contrib/ltr/src/java/org/apache/solr/ltr/feature/FieldValueFeature.java
##########
@@ -146,5 +201,137 @@ public float getMaxScore(int upTo) throws IOException {
return Float.POSITIVE_INFINITY;
}
}
+
+ /**
+ * A FeatureScorer that reads the numeric docValues for a field
+ */
+ public final class NumericDocValuesFieldValueFeatureScorer extends
FeatureScorer {
+ private final NumericDocValues docValues;
+ private final NumberType numberType;
+
+ public NumericDocValuesFieldValueFeatureScorer(final FeatureWeight
weight, final LeafReaderContext context,
+ final DocIdSetIterator itr,
final NumberType numberType) {
+ super(weight, itr);
+ this.numberType = numberType;
+
+ NumericDocValues docValues;
+ try {
+ docValues = DocValues.getNumeric(context.reader(), field);
+ } catch (IOException e) {
+ throw new IllegalArgumentException("Could not read numeric docValues
for field " + field);
+ }
+ this.docValues = docValues;
+ }
+
+ @Override
+ public float score() throws IOException {
+ if (docValues.advanceExact(itr.docID())) {
+ return readNumericDocValues();
+ }
+ return FieldValueFeature.this.getDefaultValue();
+ }
+
+ /**
+ * Read the numeric value for a field and convert the different number
types to float.
+ *
+ * @return The numeric value that the docValues contain for the current
document
+ * @throws IOException if docValues cannot be read
+ */
+ private float readNumericDocValues() throws IOException {
+ if (NumberType.FLOAT.equals(numberType)) {
+ // convert float value that was stored as long back to float
+ return Float.intBitsToFloat((int) docValues.longValue());
+ } else if (NumberType.DOUBLE.equals(numberType)) {
+ // handle double value conversion
+ return (float) Double.longBitsToDouble(docValues.longValue());
+ }
+ // just take the long value
+ return docValues.longValue();
+ }
Review comment:
Hm... the date being a numeric type really is quite unintuitive.
I am not really fond of copying the switch-logic that you referenced, but
sadly the method is private. :/
I will go and make a tea and then look into that.
Thank you for adding the test for the date field. The new clarity on what
value is returned for the date type is very good.
--
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:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]