cpoerschke commented on a change in pull request #123:
URL: https://github.com/apache/solr/pull/123#discussion_r638763122
##########
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:
Somewhat strangely so perhaps the use of `DATE` fields "just works" for
both the existing stored and the new docValues implementations. I've added a
`TestFieldValueFeature.testThatDateValuesAreCorrectlyParsed` test to
demonstrate that and so then no need to change the implementation here.
--
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]