SOLR-9890: factor out ShardResultTransformerUtils.[un]marshSortValue methods

(Judith Silverman, Christine Poerschke)
This commit is contained in:
Christine Poerschke 2017-02-14 16:52:57 +00:00
parent 5ca3ca2052
commit 787a388ec8
4 changed files with 58 additions and 27 deletions

View File

@ -202,6 +202,9 @@ Other Changes
refactoring also fixes a bug whereby PointFields were not using DocValues for range queries for
indexed=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.

View File

@ -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<Lis
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]);
}
}
searchGroup.sortValues[i] = ShardResultTransformerUtils.unmarshalSortValue(searchGroup.sortValues[i], field);
}
searchGroups.add(searchGroup);
}
@ -115,13 +109,7 @@ public class SearchGroupsResultTransformer implements ShardResultTransformer<Lis
for (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);

View File

@ -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;
}
}
}

View File

@ -174,12 +174,7 @@ public class TopGroupsResultTransformer implements ShardResultTransformer<List<C
for (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<C
Sort 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);
}