mirror of
https://github.com/apache/lucene.git
synced 2025-02-08 19:15:06 +00:00
SOLR-9890: factor out ShardResultTransformerUtils.[un]marshSortValue methods
(Judith Silverman, Christine Poerschke)
This commit is contained in:
parent
5ca3ca2052
commit
787a388ec8
@ -202,6 +202,9 @@ Other Changes
|
|||||||
refactoring also fixes a bug whereby PointFields were not using DocValues for range queries for
|
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)
|
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 ==================
|
================== 6.4.1 ==================
|
||||||
|
|
||||||
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
|
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
|
||||||
|
@ -20,7 +20,6 @@ import org.apache.lucene.search.Sort;
|
|||||||
import org.apache.lucene.search.grouping.SearchGroup;
|
import org.apache.lucene.search.grouping.SearchGroup;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.apache.solr.common.util.NamedList;
|
import org.apache.solr.common.util.NamedList;
|
||||||
import org.apache.solr.schema.FieldType;
|
|
||||||
import org.apache.solr.schema.SchemaField;
|
import org.apache.solr.schema.SchemaField;
|
||||||
import org.apache.solr.search.SolrIndexSearcher;
|
import org.apache.solr.search.SolrIndexSearcher;
|
||||||
import org.apache.solr.search.grouping.Command;
|
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()]);
|
searchGroup.sortValues = rawSearchGroup.getValue().toArray(new Comparable[rawSearchGroup.getValue().size()]);
|
||||||
for (int i = 0; i < searchGroup.sortValues.length; i++) {
|
for (int i = 0; i < searchGroup.sortValues.length; i++) {
|
||||||
SchemaField field = groupSort.getSort()[i].getField() != null ? searcher.getSchema().getFieldOrNull(groupSort.getSort()[i].getField()) : null;
|
SchemaField field = groupSort.getSort()[i].getField() != null ? searcher.getSchema().getFieldOrNull(groupSort.getSort()[i].getField()) : null;
|
||||||
if (field != null) {
|
searchGroup.sortValues[i] = ShardResultTransformerUtils.unmarshalSortValue(searchGroup.sortValues[i], field);
|
||||||
FieldType fieldType = field.getType();
|
|
||||||
if (searchGroup.sortValues[i] != null) {
|
|
||||||
searchGroup.sortValues[i] = fieldType.unmarshalSortValue(searchGroup.sortValues[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
searchGroups.add(searchGroup);
|
searchGroups.add(searchGroup);
|
||||||
}
|
}
|
||||||
@ -115,13 +109,7 @@ public class SearchGroupsResultTransformer implements ShardResultTransformer<Lis
|
|||||||
for (int i = 0; i < searchGroup.sortValues.length; i++) {
|
for (int i = 0; i < searchGroup.sortValues.length; i++) {
|
||||||
Object sortValue = searchGroup.sortValues[i];
|
Object sortValue = searchGroup.sortValues[i];
|
||||||
SchemaField field = groupSort.getSort()[i].getField() != null ? searcher.getSchema().getFieldOrNull(groupSort.getSort()[i].getField()) : null;
|
SchemaField field = groupSort.getSort()[i].getField() != null ? searcher.getSchema().getFieldOrNull(groupSort.getSort()[i].getField()) : null;
|
||||||
if (field != null) {
|
convertedSortValues[i] = ShardResultTransformerUtils.marshalSortValue(sortValue, field);
|
||||||
FieldType fieldType = field.getType();
|
|
||||||
if (sortValue != null) {
|
|
||||||
sortValue = fieldType.marshalSortValue(sortValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
convertedSortValues[i] = sortValue;
|
|
||||||
}
|
}
|
||||||
String groupValue = searchGroup.groupValue != null ? searchGroup.groupValue.utf8ToString() : null;
|
String groupValue = searchGroup.groupValue != null ? searchGroup.groupValue.utf8ToString() : null;
|
||||||
result.add(groupValue, convertedSortValues);
|
result.add(groupValue, convertedSortValues);
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -174,12 +174,7 @@ public class TopGroupsResultTransformer implements ShardResultTransformer<List<C
|
|||||||
for (int k = 0; k < sortValues.length; k++) {
|
for (int k = 0; k < sortValues.length; k++) {
|
||||||
SchemaField field = groupSort.getSort()[k].getField() != null
|
SchemaField field = groupSort.getSort()[k].getField() != null
|
||||||
? schema.getFieldOrNull(groupSort.getSort()[k].getField()) : null;
|
? schema.getFieldOrNull(groupSort.getSort()[k].getField()) : null;
|
||||||
if (field != null) {
|
sortValues[k] = ShardResultTransformerUtils.unmarshalSortValue(sortValues[k], field);
|
||||||
FieldType fieldType = field.getType();
|
|
||||||
if (sortValues[k] != null) {
|
|
||||||
sortValues[k] = fieldType.unmarshalSortValue(sortValues[k]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.debug("doc {} has null 'sortValues'", document);
|
log.debug("doc {} has null 'sortValues'", document);
|
||||||
@ -277,13 +272,7 @@ public class TopGroupsResultTransformer implements ShardResultTransformer<List<C
|
|||||||
Sort groupSort = rb.getGroupingSpec().getGroupSort();
|
Sort groupSort = rb.getGroupingSpec().getGroupSort();
|
||||||
SchemaField field = groupSort.getSort()[j].getField() != null
|
SchemaField field = groupSort.getSort()[j].getField() != null
|
||||||
? schema.getFieldOrNull(groupSort.getSort()[j].getField()) : null;
|
? schema.getFieldOrNull(groupSort.getSort()[j].getField()) : null;
|
||||||
if (field != null) {
|
convertedSortValues[j] = ShardResultTransformerUtils.marshalSortValue(sortValue, field);
|
||||||
FieldType fieldType = field.getType();
|
|
||||||
if (sortValue != null) {
|
|
||||||
sortValue = fieldType.marshalSortValue(sortValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
convertedSortValues[j] = sortValue;
|
|
||||||
}
|
}
|
||||||
document.add("sortValues", convertedSortValues);
|
document.add("sortValues", convertedSortValues);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user