diff --git a/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/SearchGroupsResultTransformer.java b/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/SearchGroupsResultTransformer.java index 8e5569bd61b..33d3c6b57be 100644 --- a/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/SearchGroupsResultTransformer.java +++ b/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/SearchGroupsResultTransformer.java @@ -88,6 +88,15 @@ public class SearchGroupsResultTransformer implements ShardResultTransformer searchGroup = new SearchGroup(); searchGroup.groupValue = rawSearchGroup.getKey() != null ? new BytesRef(rawSearchGroup.getKey()) : null; searchGroup.sortValues = rawSearchGroup.getValue().toArray(new Comparable[rawSearchGroup.getValue().size()]); + for (int i = 0; i < searchGroup.sortValues.length; i++) { + SchemaField field = groupSort.getSort()[i].getField() != null ? searcher.getSchema().getFieldOrNull(groupSort.getSort()[i].getField()) : null; + if (field != null) { + FieldType fieldType = field.getType(); + if (searchGroup.sortValues[i] != null) { + searchGroup.sortValues[i] = fieldType.unmarshalSortValue(searchGroup.sortValues[i]); + } + } + } searchGroups.add(searchGroup); } } @@ -99,22 +108,17 @@ public class SearchGroupsResultTransformer implements ShardResultTransformer> data, Sort groupSort) { - NamedList result = new NamedList(); - CharsRef spare = new CharsRef(); + NamedList result = new NamedList(); for (SearchGroup searchGroup : data) { - Comparable[] convertedSortValues = new Comparable[searchGroup.sortValues.length]; + Object[] convertedSortValues = new Object[searchGroup.sortValues.length]; for (int i = 0; i < searchGroup.sortValues.length; i++) { - Comparable sortValue = (Comparable) searchGroup.sortValues[i]; + Object sortValue = searchGroup.sortValues[i]; SchemaField field = groupSort.getSort()[i].getField() != null ? searcher.getSchema().getFieldOrNull(groupSort.getSort()[i].getField()) : null; if (field != null) { FieldType fieldType = field.getType(); - if (sortValue instanceof BytesRef) { - UnicodeUtil.UTF8toUTF16((BytesRef)sortValue, spare); - String indexedValue = spare.toString(); - sortValue = (Comparable) fieldType.toObject(field.createField(fieldType.indexedToReadable(indexedValue), 1.0f)); - } else if (sortValue instanceof String) { - sortValue = (Comparable) fieldType.toObject(field.createField(fieldType.indexedToReadable((String) sortValue), 1.0f)); + if (sortValue != null) { + sortValue = fieldType.marshalSortValue(sortValue); } } convertedSortValues[i] = sortValue; diff --git a/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/TopGroupsResultTransformer.java b/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/TopGroupsResultTransformer.java index 8e5454b6c27..1513d09e66d 100644 --- a/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/TopGroupsResultTransformer.java +++ b/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/TopGroupsResultTransformer.java @@ -93,6 +93,8 @@ public class TopGroupsResultTransformer implements ShardResultTransformer transformToNative(NamedList shardResponse, Sort groupSort, Sort sortWithinGroup, String shard) { Map result = new HashMap(); + final IndexSchema schema = rb.req.getSearcher().getSchema(); + for (Map.Entry entry : shardResponse) { String key = entry.getKey(); NamedList commandResult = entry.getValue(); @@ -124,6 +126,15 @@ public class TopGroupsResultTransformer implements ShardResultTransformer