Apache Lucene open-source search software
SOLR-9890: factor out ShardResultTransformerUtils.[un]marshSortValue methods (Judith Silverman, Christine Poerschke)
Christine Poerschke787a388ec898
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 6cd52911487..0b246664fe4 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -202,6 +202,9 @@ Other Changesrefactoring also fixes a bug whereby PointFields were not using DocValues for range queries forindexed=false, docValues=true fields. (Ishan Chattopadhyaya, Tomás Fernández Löbbe)+* SOLR-9890: factor out ShardResultTransformerUtils.[un]marshSortValue methods+ (Judith Silverman, Christine Poerschke)+================== 6.4.1 ==================Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.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.javaindex 213414a37ec..c5c1e811970 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@@ -20,7 +20,6 @@ import org.apache.lucene.search.Sort;import org.apache.lucene.search.grouping.SearchGroup;import org.apache.lucene.util.BytesRef;import org.apache.solr.common.util.NamedList;-import org.apache.solr.schema.FieldType;import org.apache.solr.schema.SchemaField;import org.apache.solr.search.SolrIndexSearcher;import org.apache.solr.search.grouping.Command;@@ -90,12 +89,7 @@ public class SearchGroupsResultTransformer implements ShardResultTransformer<LissearchGroup.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]);- }- }+ searchGroup.sortValues[i] = ShardResultTransformerUtils.unmarshalSortValue(searchGroup.sortValues[i], field);}searchGroups.add(searchGroup);}@@ -115,13 +109,7 @@ public class SearchGroupsResultTransformer implements ShardResultTransformer<Lisfor (int i = 0; i < searchGroup.sortValues.length; 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 != null) {- sortValue = fieldType.marshalSortValue(sortValue);- }- }- convertedSortValues[i] = sortValue;+ convertedSortValues[i] = ShardResultTransformerUtils.marshalSortValue(sortValue, field);}String groupValue = searchGroup.groupValue != null ? searchGroup.groupValue.utf8ToString() : null;result.add(groupValue, convertedSortValues);diff --git a/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/ShardResultTransformerUtils.java b/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/ShardResultTransformerUtils.javanew file mode 100644index 00000000000..df0604c5b5c--- /dev/null+++ b/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/ShardResultTransformerUtils.java@@ -0,0 +1,51 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package org.apache.solr.search.grouping.distributed.shardresultserializer;++import org.apache.solr.schema.FieldType;+import org.apache.solr.schema.SchemaField;++/**+ * Utility functions used by implementations of the {@link ShardResultTransformer} interface.+ *+ * @lucene.experimental+ */+class ShardResultTransformerUtils {++ static Object marshalSortValue(Object originalSortValue, SchemaField schemaField) {+ return marshalOrUnmarshalSortValue(originalSortValue, schemaField, true);+ }++ static Object unmarshalSortValue(Object originalSortValue, SchemaField schemaField) {+ return marshalOrUnmarshalSortValue(originalSortValue, schemaField, false);+ }++ private static Object marshalOrUnmarshalSortValue(Object originalSortValue, SchemaField schemaField,+ boolean marshal) {+ if (originalSortValue != null && schemaField != null) {+ final FieldType fieldType = schemaField.getType();+ if (marshal) {+ return fieldType.marshalSortValue(originalSortValue);+ } else {+ return fieldType.unmarshalSortValue(originalSortValue);+ }+ } else {+ return originalSortValue;+ }+ }++}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.javaindex 37e837e664e..3ff87bd83ed 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@@ -174,12 +174,7 @@ public class TopGroupsResultTransformer implements ShardResultTransformer<List<Cfor (int k = 0; k < sortValues.length; k++) {SchemaField field = groupSort.getSort()[k].getField() != null? schema.getFieldOrNull(groupSort.getSort()[k].getField()) : null;- if (field != null) {- FieldType fieldType = field.getType();- if (sortValues[k] != null) {- sortValues[k] = fieldType.unmarshalSortValue(sortValues[k]);- }- }+ sortValues[k] = ShardResultTransformerUtils.unmarshalSortValue(sortValues[k], field);}} else {log.debug("doc {} has null 'sortValues'", document);@@ -277,13 +272,7 @@ public class TopGroupsResultTransformer implements ShardResultTransformer<List<CSort groupSort = rb.getGroupingSpec().getGroupSort();SchemaField field = groupSort.getSort()[j].getField() != null? schema.getFieldOrNull(groupSort.getSort()[j].getField()) : null;- if (field != null) {- FieldType fieldType = field.getType();- if (sortValue != null) {- sortValue = fieldType.marshalSortValue(sortValue);- }- }- convertedSortValues[j] = sortValue;+ convertedSortValues[j] = ShardResultTransformerUtils.marshalSortValue(sortValue, field);}document.add("sortValues", convertedSortValues);}