org.apache.solr.update.processor.MaxFieldValueUpdateProcessorFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of solr-core Show documentation
Show all versions of solr-core Show documentation
Apache Solr (module: core)
/*
* 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.update.processor;
import static org.apache.solr.common.SolrException.ErrorCode.BAD_REQUEST;
import static org.apache.solr.update.processor.FieldMutatingUpdateProcessor.SELECT_NO_FIELDS;
import java.util.Collection;
import java.util.Collections;
import org.apache.solr.common.SolrException;
import org.apache.solr.core.SolrCore;
import org.apache.solr.update.processor.FieldMutatingUpdateProcessor.FieldNameSelector;
/**
* An update processor that keeps only the maximum value from any selected fields where multiple
* values are found. Correct behavior requires tha all of the values in the SolrInputFields being
* mutated are mutually comparable; If this is not the case, then a SolrException will br thrown.
*
* By default, this processor matches no fields.
*
*
In the example configuration below, if a document contains multiple integer values (ie:
* 64, 128, 1024
) in the field largestFileSize
then only the biggest value (ie:
* 1024
) will be kept in that field.
*
*
* <processor class="solr.MaxFieldValueUpdateProcessorFactory">
* <str name="fieldName">largestFileSize</str>
* </processor>
*
*
* @see MinFieldValueUpdateProcessorFactory
* @see Collections#max
* @since 4.0.0
*/
public final class MaxFieldValueUpdateProcessorFactory
extends FieldValueSubsetUpdateProcessorFactory {
@Override
public Collection pickSubset(Collection values) {
try {
// Use the signature with null comparator to let the JDK deal with unsafe casts, and catch CCE
// if needed
return Collections.singletonList(Collections.max(values, null));
} catch (ClassCastException e) {
throw new SolrException(
BAD_REQUEST, "Field values are not mutually comparable: " + e.getMessage(), e);
}
}
@Override
public FieldNameSelector getDefaultSelector(SolrCore core) {
return SELECT_NO_FIELDS;
}
}