diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index ff06ae857a0..a9731e16f9a 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -348,6 +348,9 @@ Bug Fixes * SOLR-8886: Fix TrieField.toObject(IndexableField) to work for field with docValues enabled. (yonik) +* SOLR-8891: Fix StrField.toObject and toExternal to work with docValue IndexableField + instances. (yonik) + Optimizations ---------------------- * SOLR-7876: Speed up queries and operations that use many terms when timeAllowed has not been diff --git a/solr/core/src/java/org/apache/solr/schema/FieldType.java b/solr/core/src/java/org/apache/solr/schema/FieldType.java index fbcebcda1b1..ab89f94c575 100644 --- a/solr/core/src/java/org/apache/solr/schema/FieldType.java +++ b/solr/core/src/java/org/apache/solr/schema/FieldType.java @@ -353,7 +353,12 @@ public abstract class FieldType extends FieldProperties { // currently used in writing XML of the search result (but perhaps // a more efficient toXML(IndexableField f, Writer w) should be used // in the future. - return f.stringValue(); + String val = f.stringValue(); + if (val == null) { + // docValues will use the binary value + val = f.binaryValue().utf8ToString(); + } + return val; } /** diff --git a/solr/core/src/java/org/apache/solr/schema/StrField.java b/solr/core/src/java/org/apache/solr/schema/StrField.java index 8aa8ecfff06..7bda94336dd 100644 --- a/solr/core/src/java/org/apache/solr/schema/StrField.java +++ b/solr/core/src/java/org/apache/solr/schema/StrField.java @@ -40,21 +40,29 @@ public class StrField extends PrimitiveFieldType { } @Override - public List createFields(SchemaField field, Object value, - float boost) { + public List createFields(SchemaField field, Object value, float boost) { + IndexableField fval = createField(field, value, boost); + if (field.hasDocValues()) { - List fields = new ArrayList<>(); - fields.add(createField(field, value, boost)); + IndexableField docval; final BytesRef bytes = new BytesRef(value.toString()); if (field.multiValued()) { - fields.add(new SortedSetDocValuesField(field.getName(), bytes)); + docval = new SortedSetDocValuesField(field.getName(), bytes); } else { - fields.add(new SortedDocValuesField(field.getName(), bytes)); + docval = new SortedDocValuesField(field.getName(), bytes); } - return fields; - } else { - return Collections.singletonList(createField(field, value, boost)); + + // Only create a list of we have 2 values... + if (fval != null) { + List fields = new ArrayList<>(2); + fields.add(fval); + fields.add(docval); + return fields; + } + + fval = docval; } + return Collections.singletonList(fval); } @Override diff --git a/solr/core/src/test/org/apache/solr/schema/DocValuesTest.java b/solr/core/src/test/org/apache/solr/schema/DocValuesTest.java index 2537c8f0f6d..6411a834b35 100644 --- a/solr/core/src/test/org/apache/solr/schema/DocValuesTest.java +++ b/solr/core/src/test/org/apache/solr/schema/DocValuesTest.java @@ -116,7 +116,9 @@ public class DocValuesTest extends SolrTestCaseJ4 { tstToObj(schema.getField("longdvs"), -11L); tstToObj(schema.getField("datedv"), new Date(1000)); tstToObj(schema.getField("datedvs"), new Date(1000)); - + tstToObj(schema.getField("stringdv"), "foo"); + tstToObj(schema.getField("stringdvs"), "foo"); + } finally { searcherRef.decref(); }