gerlowskija commented on code in PR #4645:
URL: https://github.com/apache/solr/pull/4645#discussion_r3690551225


##########
solr/core/src/java/org/apache/solr/schema/numericrange/AbstractNumericRangeField.java:
##########
@@ -153,34 +172,120 @@ protected void init(IndexSchema schema, Map<String, 
String> args) {
                 + typeName);
       }
     }
+  }
 
-    // Range fields do not support docValues - validate this wasn't explicitly 
enabled
-    if (hasProperty(DOC_VALUES)) {
-      throw new SolrException(
-          ErrorCode.SERVER_ERROR,
-          "docValues=true enabled but "
-              + getClass().getSimpleName()
-              + " does not support docValues for field type "
-              + typeName);
-    }
+  @Override
+  protected void checkSupportsDocValues() {
+    // DocValues are supported for both single and multiValued range fields 
(backed by binary
+    // docValues).
   }
 
   @Override
   public List<IndexableField> createFields(SchemaField field, Object value) {
-    IndexableField indexedField = createField(field, value);
     List<IndexableField> fields = new ArrayList<>();
 
+    IndexableField indexedField = createField(field, value);
     if (indexedField != null) {
       fields.add(indexedField);
     }
 
+    if (field.hasDocValues() && !field.multiValued()) {
+      // Single-valued: one flat BinaryDocValues blob (read directly, no 
dictionary). multiValued
+      // docValues are built from all values at once in 
createFieldsFromAllValues (one blob holding
+      // every range), since BinaryDocValues holds only one value per document.
+      NumericRangeValue rv = parseRangeValue(value.toString());
+      fields.add(
+          new BinaryDocValuesField(
+              field.getName(), 
BytesRef.deepCopyOf(encodePackedValue(field.getName(), rv))));
+    }
+
     if (field.stored()) {
       fields.add(getStoredField(field, value.toString()));
     }
 
     return fields;
   }
 
+  @Override
+  public boolean shouldCreateFieldsFromAllValues() {
+    // multiValued docValues range fields pack every range of a document into 
ONE BinaryDocValues
+    // blob (flat, no dictionary), so the type needs all values together to 
build it.
+    return true;
+  }
+
+  @Override
+  public List<IndexableField> createFieldsFromAllValues(
+      SchemaField field, Collection<Object> values) {

Review Comment:
   [Q] Should we sort the provided values in some way prior to encoding?  
Having the values sorted would allow some future optimizations in the docValues 
query logic, where we could avoid looking at each and every field value in some 
cases.
   
   e.g. Given a document with field values `[3 TO 4]`, `[7 TO 8]`, `[11 TO 
12]`....if values were sorted in ascending , a docValues query could probably 
skip over the latter two field values entirely for a query like `{!numericRange 
type=contains}[1 TO 2]`
   
   The query optimization might be complex and beyond the scope for this PR, 
but IMO it'd make sense to put the sorting in now so that further optimization 
is at least possible down the road. Wdyt?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to