serba commented on code in PR #2536:
URL: https://github.com/apache/solr/pull/2536#discussion_r1673447557


##########
solr/core/src/java/org/apache/solr/schema/BinaryField.java:
##########
@@ -112,7 +125,31 @@ public IndexableField createField(SchemaField field, 
Object val) {
       len = buf.length;
     }
 
-    return new org.apache.lucene.document.StoredField(field.getName(), buf, 
offset, len);
+    return new BytesRef(buf, offset, len);
+  }
+
+  @Override
+  public List<IndexableField> createFields(SchemaField field, Object val) {
+    IndexableField fval = createField(field, val);
+
+    if (field.hasDocValues() && !field.multiValued()) {
+      IndexableField docval = new BinaryDocValuesField(field.getName(), 
getBytesRef(val));
+
+      // Only create list if we have 2 values...
+      if (fval != null) {
+        List<IndexableField> fields = new ArrayList<>(2);
+        fields.add(fval);
+        fields.add(docval);
+        return fields;
+      }
+
+      fval = docval;
+    }
+    return Collections.singletonList(fval);

Review Comment:
   Yeah, my understanding is that this code is getting executed every time the 
field of this type is being indexed.
   
   I borrowed the code from `StrField` type that supports creating `stored` 
and/or `docValued` Lucene fields for a single Solr field and there were such 
optimizations to create an `ArrayList` only in case of when both `stored` and 
`docValues` options are enabled. 
   
   I guess it makes sense to keep this code consistent across different field 
types until there's some appetite in rewriting this in `streams` or `List.of` 
style across the board.



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