SOLR-8995: Use lamdas in URPs

This commit is contained in:
Noble Paul 2016-09-22 15:29:07 +05:30
parent d146354457
commit 80336a278a
22 changed files with 262 additions and 315 deletions

View File

@ -16,6 +16,17 @@
*/
package org.apache.solr.update.processor;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.SolrInputField;
@ -28,23 +39,12 @@ import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.ManagedIndexSchema;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.update.AddUpdateCommand;
import org.apache.solr.update.processor.FieldMutatingUpdateProcessorFactory.SelectorParams;
import org.apache.solr.update.processor.FieldMutatingUpdateProcessor.FieldNameSelector;
import org.apache.solr.update.processor.FieldMutatingUpdateProcessorFactory.SelectorParams;
import org.apache.solr.util.plugin.SolrCoreAware;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.apache.solr.common.SolrException.ErrorCode.BAD_REQUEST;
import static org.apache.solr.common.SolrException.ErrorCode.SERVER_ERROR;
import static org.apache.solr.core.ConfigSetProperties.IMMUTABLE_CONFIGSET_ARG;
@ -384,18 +384,9 @@ public class AddSchemaFieldsUpdateProcessorFactory extends UpdateRequestProcesso
return defaultFieldType;
}
private FieldNameSelector getDefaultSelector(final IndexSchema schema) {
return new FieldNameSelector() {
@Override
public boolean shouldMutate(final String fieldName) {
return null == schema.getFieldTypeNoEx(fieldName);
}
};
}
private FieldNameSelector buildSelector(IndexSchema schema) {
FieldNameSelector selector = FieldMutatingUpdateProcessor.createFieldNameSelector
(solrResourceLoader, schema, inclusions, getDefaultSelector(schema));
(solrResourceLoader, schema, inclusions, fieldName -> null == schema.getFieldTypeNoEx(fieldName));
for (SelectorParams exc : exclusions) {
selector = FieldMutatingUpdateProcessor.wrap(selector, FieldMutatingUpdateProcessor.createFieldNameSelector

View File

@ -16,19 +16,19 @@
*/
package org.apache.solr.update.processor;
import org.apache.solr.core.SolrCore;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.FieldType;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.schema.TextField;
import org.apache.solr.schema.StrField;
import org.apache.commons.lang.StringUtils;
import org.apache.solr.common.SolrInputField;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.SolrCore;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.schema.FieldType;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.schema.StrField;
import org.apache.solr.schema.TextField;
import org.apache.commons.lang.StringUtils;
import static org.apache.solr.update.processor.FieldMutatingUpdateProcessor.mutator;
/**
* Concatenates multiple values for fields matching the specified
@ -77,44 +77,38 @@ public final class ConcatFieldUpdateProcessorFactory extends FieldMutatingUpdate
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
SolrQueryResponse rsp,
UpdateRequestProcessor next) {
return new FieldMutatingUpdateProcessor(getSelector(), next) {
@Override
protected SolrInputField mutate(final SolrInputField src) {
if (src.getValueCount() <= 1) return src;
return mutator(getSelector(), next, src -> {
if (src.getValueCount() <= 1) return src;
SolrInputField result = new SolrInputField(src.getName());
result.setValue(StringUtils.join(src.getValues(), delimiter),
src.getBoost());
return result;
}
};
SolrInputField result = new SolrInputField(src.getName());
result.setValue(StringUtils.join(src.getValues(), delimiter),
src.getBoost());
return result;
});
}
@Override
public FieldMutatingUpdateProcessor.FieldNameSelector
getDefaultSelector(final SolrCore core) {
return new FieldMutatingUpdateProcessor.FieldNameSelector() {
@Override
public boolean shouldMutate(final String fieldName) {
final IndexSchema schema = core.getLatestSchema();
return fieldName -> {
final IndexSchema schema = core.getLatestSchema();
// first check type since it should be fastest
FieldType type = schema.getFieldTypeNoEx(fieldName);
if (null == type) return false;
if (! (TextField.class.isInstance(type)
|| StrField.class.isInstance(type))) {
return false;
}
// first check type since it should be fastest
FieldType type = schema.getFieldTypeNoEx(fieldName);
if (null == type) return false;
// only ask for SchemaField if we passed the type check.
SchemaField sf = schema.getFieldOrNull(fieldName);
// shouldn't be null since since type wasn't, but just in case
if (null == sf) return false;
return ! sf.multiValued();
if (! (TextField.class.isInstance(type)
|| StrField.class.isInstance(type))) {
return false;
}
// only ask for SchemaField if we passed the type check.
SchemaField sf = schema.getFieldOrNull(fieldName);
// shouldn't be null since since type wasn't, but just in case
if (null == sf) return false;
return ! sf.multiValued();
};
}

View File

@ -20,6 +20,8 @@ import org.apache.solr.common.SolrInputField;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
import static org.apache.solr.update.processor.FieldMutatingUpdateProcessor.mutator;
/**
* <p>
* Replaces any list of values for a field matching the specified
@ -68,15 +70,12 @@ public final class CountFieldValuesUpdateProcessorFactory extends FieldMutatingU
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
SolrQueryResponse rsp,
UpdateRequestProcessor next) {
return new FieldMutatingUpdateProcessor(getSelector(), next) {
@Override
protected SolrInputField mutate(final SolrInputField src) {
SolrInputField result = new SolrInputField(src.getName());
result.setValue(src.getValueCount(),
src.getBoost());
return result;
}
};
return mutator(getSelector(), next, src -> {
SolrInputField result = new SolrInputField(src.getName());
result.setValue(src.getValueCount(),
src.getBoost());
return result;
});
}
}

View File

@ -17,9 +17,13 @@
package org.apache.solr.update.processor;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.SolrCore;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.core.SolrCore;
import org.apache.solr.update.processor.FieldMutatingUpdateProcessor.FieldNameSelector;
import static org.apache.solr.update.processor.FieldMutatingUpdateProcessor.SELECT_NO_FIELDS;
import static org.apache.solr.update.processor.FieldValueMutatingUpdateProcessor.valueMutator;
/**
@ -54,26 +58,21 @@ public final class FieldLengthUpdateProcessorFactory extends FieldMutatingUpdate
}
@Override
public FieldMutatingUpdateProcessor.FieldNameSelector
getDefaultSelector(final SolrCore core) {
return FieldMutatingUpdateProcessor.SELECT_NO_FIELDS;
public FieldNameSelector getDefaultSelector(final SolrCore core) {
return SELECT_NO_FIELDS;
}
@Override
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
SolrQueryResponse rsp,
UpdateRequestProcessor next) {
return new FieldValueMutatingUpdateProcessor(getSelector(), next) {
@Override
protected Object mutateValue(final Object src) {
if (src instanceof CharSequence) {
return new Integer(((CharSequence)src).length());
}
return src;
return valueMutator(getSelector(), next, src -> {
if (src instanceof CharSequence) {
return ((CharSequence) src).length();
}
};
return src;
});
}
}

View File

@ -20,15 +20,12 @@ import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collection;
import java.util.function.Function;
import java.util.regex.Pattern;
import static org.apache.solr.common.SolrException.ErrorCode.BAD_REQUEST;
import static org.apache.solr.common.SolrException.ErrorCode.SERVER_ERROR;
import static org.apache.solr.update.processor.FieldMutatingUpdateProcessorFactory.SelectorParams;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.SolrInputField;
import org.apache.solr.common.SolrException;
import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrResourceLoader;
import org.apache.solr.schema.FieldType;
@ -37,6 +34,10 @@ import org.apache.solr.update.AddUpdateCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.solr.common.SolrException.ErrorCode.BAD_REQUEST;
import static org.apache.solr.common.SolrException.ErrorCode.SERVER_ERROR;
import static org.apache.solr.update.processor.FieldMutatingUpdateProcessorFactory.SelectorParams;
/**
* Reusable base class for UpdateProcessors that will consider
* AddUpdateCommands and mutate the values associated with configured
@ -120,27 +121,15 @@ public abstract class FieldMutatingUpdateProcessor
/**
* Interface for identifying which fields should be mutated
*/
public static interface FieldNameSelector {
public boolean shouldMutate(final String fieldName);
public interface FieldNameSelector {
boolean shouldMutate(final String fieldName);
}
/** Singleton indicating all fields should be mutated */
public static final FieldNameSelector SELECT_ALL_FIELDS
= new FieldNameSelector() {
@Override
public boolean shouldMutate(final String fieldName) {
return true;
}
};
public static final FieldNameSelector SELECT_ALL_FIELDS = fieldName -> true;
/** Singleton indicating no fields should be mutated */
public static final FieldNameSelector SELECT_NO_FIELDS
= new FieldNameSelector() {
@Override
public boolean shouldMutate(final String fieldName) {
return false;
}
};
public static final FieldNameSelector SELECT_NO_FIELDS = fieldName -> false;
/**
* Wraps two FieldNameSelectors such that the FieldNameSelector
@ -165,21 +154,11 @@ public abstract class FieldMutatingUpdateProcessor
}
if (SELECT_ALL_FIELDS == includes) {
return new FieldNameSelector() {
@Override
public boolean shouldMutate(final String fieldName) {
return ! excludes.shouldMutate(fieldName);
}
};
return fieldName -> ! excludes.shouldMutate(fieldName);
}
return new FieldNameSelector() {
@Override
public boolean shouldMutate(final String fieldName) {
return (includes.shouldMutate(fieldName)
&& ! excludes.shouldMutate(fieldName));
}
};
return fieldName -> (includes.shouldMutate(fieldName)
&& ! excludes.shouldMutate(fieldName));
}
/**
@ -201,12 +180,7 @@ public abstract class FieldMutatingUpdateProcessor
final ConfigurableFieldNameSelectorHelper helper =
new ConfigurableFieldNameSelectorHelper(loader, params);
return new FieldNameSelector() {
@Override
public boolean shouldMutate(String fieldName) {
return helper.shouldMutateBasedOnSchema(fieldName, core.getLatestSchema());
}
};
return fieldName -> helper.shouldMutateBasedOnSchema(fieldName, core.getLatestSchema());
}
/**
@ -229,12 +203,7 @@ public abstract class FieldMutatingUpdateProcessor
final ConfigurableFieldNameSelectorHelper helper =
new ConfigurableFieldNameSelectorHelper(loader, params);
return new FieldNameSelector() {
@Override
public boolean shouldMutate(String fieldName) {
return helper.shouldMutateBasedOnSchema(fieldName, schema);
}
};
return fieldName -> helper.shouldMutateBasedOnSchema(fieldName, schema);
}
private static final class ConfigurableFieldNameSelectorHelper {
@ -317,5 +286,16 @@ public abstract class FieldMutatingUpdateProcessor
return false;
}
}
public static FieldMutatingUpdateProcessor mutator(FieldNameSelector selector,
UpdateRequestProcessor next,
Function<SolrInputField,SolrInputField> fun){
return new FieldMutatingUpdateProcessor(selector, next) {
@Override
protected SolrInputField mutate(SolrInputField src) {
return fun.apply(src);
}
};
}
}

View File

@ -28,8 +28,11 @@ import java.util.regex.PatternSyntaxException;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.SolrCore;
import org.apache.solr.update.processor.FieldMutatingUpdateProcessor.FieldNameSelector;
import org.apache.solr.util.plugin.SolrCoreAware;
import static org.apache.solr.update.processor.FieldMutatingUpdateProcessor.SELECT_ALL_FIELDS;
/**
* Base class for implementing Factories for FieldMutatingUpdateProcessors and
@ -101,7 +104,7 @@ import org.apache.solr.util.plugin.SolrCoreAware;
*
* @see FieldMutatingUpdateProcessor
* @see FieldValueMutatingUpdateProcessor
* @see FieldMutatingUpdateProcessor.FieldNameSelector
* @see FieldNameSelector
*/
public abstract class FieldMutatingUpdateProcessorFactory
extends UpdateRequestProcessorFactory
@ -125,9 +128,9 @@ public abstract class FieldMutatingUpdateProcessorFactory
private Collection<SelectorParams> exclusions
= new ArrayList<>();
private FieldMutatingUpdateProcessor.FieldNameSelector selector = null;
private FieldNameSelector selector = null;
protected final FieldMutatingUpdateProcessor.FieldNameSelector getSelector() {
protected final FieldNameSelector getSelector() {
if (null != selector) return selector;
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
@ -234,10 +237,7 @@ public abstract class FieldMutatingUpdateProcessorFactory
*
* @see FieldMutatingUpdateProcessor#SELECT_ALL_FIELDS
*/
protected FieldMutatingUpdateProcessor.FieldNameSelector
getDefaultSelector(final SolrCore core) {
return FieldMutatingUpdateProcessor.SELECT_ALL_FIELDS;
protected FieldNameSelector getDefaultSelector(SolrCore core) {
return SELECT_ALL_FIELDS;
}
}

View File

@ -18,6 +18,7 @@ package org.apache.solr.update.processor;
import java.lang.invoke.MethodHandles;
import java.util.Collection;
import java.util.function.Function;
import org.apache.solr.common.SolrInputField;
@ -83,5 +84,16 @@ public abstract class FieldValueMutatingUpdateProcessor
result.setBoost(src.getBoost());
return 0 == result.getValueCount() ? null : result;
}
public static FieldValueMutatingUpdateProcessor valueMutator(FieldNameSelector selector,
UpdateRequestProcessor next,
Function<Object, Object> fun) {
return new FieldValueMutatingUpdateProcessor(selector, next) {
@Override
protected Object mutateValue(Object src) {
return fun.apply(src);
}
};
}
}

View File

@ -16,11 +16,13 @@
*/
package org.apache.solr.update.processor;
import java.util.Collection;
import org.apache.solr.common.SolrInputField;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
import java.util.Collection;
import static org.apache.solr.update.processor.FieldMutatingUpdateProcessor.mutator;
/**
* Base class for processors that want to mutate selected fields to only
@ -33,17 +35,14 @@ public abstract class FieldValueSubsetUpdateProcessorFactory extends FieldMutati
public final UpdateRequestProcessor getInstance(SolrQueryRequest req,
SolrQueryResponse rsp,
UpdateRequestProcessor next) {
return new FieldMutatingUpdateProcessor(getSelector(), next) {
@Override
protected SolrInputField mutate(final SolrInputField src) {
if (src.getValueCount() <= 1) return src;
return mutator(getSelector(), next, src -> {
if (src.getValueCount() <= 1) return src;
SolrInputField result = new SolrInputField(src.getName());
result.setValue(pickSubset(src.getValues()),
src.getBoost());
return result;
}
};
SolrInputField result = new SolrInputField(src.getName());
result.setValue(pickSubset(src.getValues()),
src.getBoost());
return result;
});
}
/**

View File

@ -16,10 +16,13 @@
*/
package org.apache.solr.update.processor;
import org.apache.solr.core.SolrCore;
import java.util.Collections;
import java.util.Collection;
import java.util.Collections;
import org.apache.solr.core.SolrCore;
import org.apache.solr.update.processor.FieldMutatingUpdateProcessor.FieldNameSelector;
import static org.apache.solr.update.processor.FieldMutatingUpdateProcessor.SELECT_NO_FIELDS;
/**
* Keeps only the first value of fields matching the specified
@ -53,10 +56,8 @@ public final class FirstFieldValueUpdateProcessorFactory extends FieldValueSubse
}
@Override
public FieldMutatingUpdateProcessor.FieldNameSelector
getDefaultSelector(final SolrCore core) {
return FieldMutatingUpdateProcessor.SELECT_NO_FIELDS;
public FieldNameSelector getDefaultSelector(SolrCore core) {
return SELECT_NO_FIELDS;
}
}

View File

@ -16,18 +16,19 @@
*/
package org.apache.solr.update.processor;
import org.apache.solr.core.SolrCore;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.lucene.analysis.charfilter.HTMLStripCharFilter;
import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import org.apache.commons.io.IOUtils;
import org.apache.lucene.analysis.charfilter.HTMLStripCharFilter;
import org.apache.solr.core.SolrCore;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
import static org.apache.solr.update.processor.FieldValueMutatingUpdateProcessor.valueMutator;
/**
* Strips all HTML Markup in any CharSequence values
* found in fields matching the specified conditions.
@ -58,29 +59,25 @@ public final class HTMLStripFieldUpdateProcessorFactory extends FieldMutatingUpd
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
SolrQueryResponse rsp,
UpdateRequestProcessor next) {
return new FieldValueMutatingUpdateProcessor(getSelector(), next) {
@Override
protected Object mutateValue(final Object src) {
if (src instanceof CharSequence) {
CharSequence s = (CharSequence)src;
StringWriter result = new StringWriter(s.length());
Reader in = null;
try {
in = new HTMLStripCharFilter
return valueMutator(getSelector(), next, src -> {
if (src instanceof CharSequence) {
CharSequence s = (CharSequence) src;
StringWriter result = new StringWriter(s.length());
Reader in = null;
try {
in = new HTMLStripCharFilter
(new StringReader(s.toString()));
IOUtils.copy(in, result);
return result.toString();
} catch (IOException e) {
// we tried and failed
return s;
} finally {
IOUtils.closeQuietly(in);
}
IOUtils.copy(in, result);
return result.toString();
} catch (IOException e) {
// we tried and failed
return s;
} finally {
IOUtils.closeQuietly(in);
}
return src;
}
};
return src;
});
}
}

View File

@ -17,12 +17,13 @@
package org.apache.solr.update.processor;
import org.apache.solr.core.SolrCore;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.FieldType;
import org.apache.solr.common.SolrInputField;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.schema.FieldType;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.update.processor.FieldMutatingUpdateProcessor.FieldNameSelector;
import static org.apache.solr.update.processor.FieldMutatingUpdateProcessor.mutator;
/**
* Ignores &amp; removes fields matching the specified
@ -57,26 +58,16 @@ public final class IgnoreFieldUpdateProcessorFactory extends FieldMutatingUpdate
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
SolrQueryResponse rsp,
UpdateRequestProcessor next) {
return new FieldMutatingUpdateProcessor(getSelector(), next) {
@Override
protected SolrInputField mutate(final SolrInputField src) {
return null;
}
};
return mutator(getSelector(), next, src -> null);
}
@Override
public FieldMutatingUpdateProcessor.FieldNameSelector
getDefaultSelector(final SolrCore core) {
return new FieldMutatingUpdateProcessor.FieldNameSelector() {
@Override
public boolean shouldMutate(final String fieldName) {
final IndexSchema schema = core.getLatestSchema();
FieldType type = schema.getFieldTypeNoEx(fieldName);
return (null == type);
}
public FieldNameSelector getDefaultSelector(final SolrCore core) {
return fieldName -> {
final IndexSchema schema = core.getLatestSchema();
FieldType type = schema.getFieldTypeNoEx(fieldName);
return (null == type);
};
}

View File

@ -17,12 +17,15 @@
package org.apache.solr.update.processor;
import org.apache.solr.core.SolrCore;
import org.apache.solr.update.processor.FieldMutatingUpdateProcessor.FieldNameSelector;
import java.util.Collections;
import java.util.Collection;
import java.util.List;
import java.util.SortedSet;
import static org.apache.solr.update.processor.FieldMutatingUpdateProcessor.SELECT_NO_FIELDS;
/**
* Keeps only the last value of fields matching the specified
* conditions. Correct behavior assumes that the SolrInputFields being mutated
@ -69,10 +72,8 @@ public final class LastFieldValueUpdateProcessorFactory extends FieldValueSubset
}
@Override
public FieldMutatingUpdateProcessor.FieldNameSelector
getDefaultSelector(final SolrCore core) {
return FieldMutatingUpdateProcessor.SELECT_NO_FIELDS;
public FieldNameSelector getDefaultSelector(final SolrCore core) {
return SELECT_NO_FIELDS;
}
}

View File

@ -16,14 +16,15 @@
*/
package org.apache.solr.update.processor;
import static org.apache.solr.common.SolrException.ErrorCode.*;
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;
import java.util.Collections;
import java.util.Collection;
import static org.apache.solr.common.SolrException.ErrorCode.BAD_REQUEST;
import static org.apache.solr.update.processor.FieldMutatingUpdateProcessor.SELECT_NO_FIELDS;
/**
* An update processor that keeps only the the maximum value from any selected
@ -59,7 +60,7 @@ public final class MaxFieldValueUpdateProcessorFactory extends FieldValueSubsetU
try {
// NOTE: the extra cast to Object is needed to prevent compile
// errors on Eclipse Compiler (ecj) used for javadoc lint
result = Collections.singletonList((Object) Collections.max(values));
result = Collections.singletonList(Collections.max(values));
} catch (ClassCastException e) {
throw new SolrException
(BAD_REQUEST,
@ -69,10 +70,8 @@ public final class MaxFieldValueUpdateProcessorFactory extends FieldValueSubsetU
}
@Override
public FieldMutatingUpdateProcessor.FieldNameSelector
getDefaultSelector(final SolrCore core) {
return FieldMutatingUpdateProcessor.SELECT_NO_FIELDS;
public FieldNameSelector getDefaultSelector(SolrCore core) {
return SELECT_NO_FIELDS;
}
}

View File

@ -16,14 +16,15 @@
*/
package org.apache.solr.update.processor;
import static org.apache.solr.common.SolrException.ErrorCode.*;
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;
import java.util.Collections;
import java.util.Collection;
import static org.apache.solr.common.SolrException.ErrorCode.BAD_REQUEST;
import static org.apache.solr.update.processor.FieldMutatingUpdateProcessor.SELECT_NO_FIELDS;
/**
* An update processor that keeps only the the minimum value from any selected
@ -59,7 +60,7 @@ public final class MinFieldValueUpdateProcessorFactory extends FieldValueSubsetU
try {
// NOTE: the extra cast to Object is needed to prevent compile
// errors on Eclipse Compiler (ecj) used for javadoc lint
result = Collections.singletonList((Object) Collections.min(values));
result = Collections.singletonList(Collections.min(values));
} catch (ClassCastException e) {
throw new SolrException
(BAD_REQUEST,
@ -69,10 +70,8 @@ public final class MinFieldValueUpdateProcessorFactory extends FieldValueSubsetU
}
@Override
public FieldMutatingUpdateProcessor.FieldNameSelector
getDefaultSelector(final SolrCore core) {
return FieldMutatingUpdateProcessor.SELECT_NO_FIELDS;
public FieldNameSelector getDefaultSelector(SolrCore core) {
return SELECT_NO_FIELDS;
}
}

View File

@ -16,6 +16,13 @@
*/
package org.apache.solr.update.processor;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.util.NamedList;
@ -25,12 +32,7 @@ import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.schema.BoolField;
import org.apache.solr.schema.FieldType;
import org.apache.solr.schema.IndexSchema;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import org.apache.solr.update.processor.FieldMutatingUpdateProcessor.FieldNameSelector;
/**
* <p>
@ -141,16 +143,11 @@ public class ParseBooleanFieldUpdateProcessorFactory extends FieldMutatingUpdate
* or if the matched field's type is BoolField
*/
@Override
public FieldMutatingUpdateProcessor.FieldNameSelector
getDefaultSelector(final SolrCore core) {
return new FieldMutatingUpdateProcessor.FieldNameSelector() {
@Override
public boolean shouldMutate(final String fieldName) {
final IndexSchema schema = core.getLatestSchema();
FieldType type = schema.getFieldTypeNoEx(fieldName);
return (null == type) || (type instanceof BoolField);
}
public FieldNameSelector getDefaultSelector(final SolrCore core) {
return fieldName -> {
final IndexSchema schema = core.getLatestSchema();
FieldType type = schema.getFieldTypeNoEx(fieldName);
return (null == type) || (type instanceof BoolField);
};
}
}

View File

@ -16,6 +16,13 @@
*/
package org.apache.solr.update.processor;
import java.lang.invoke.MethodHandles;
import java.util.Collection;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import org.apache.commons.lang.LocaleUtils;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.SolrCore;
@ -31,13 +38,6 @@ import org.joda.time.format.DateTimeFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.invoke.MethodHandles;
import java.util.Collection;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
/**
* <p>
* Attempts to mutate selected fields that have only CharSequence-typed values
@ -165,13 +165,10 @@ public class ParseDateFieldUpdateProcessorFactory extends FieldMutatingUpdatePro
public FieldMutatingUpdateProcessor.FieldNameSelector
getDefaultSelector(final SolrCore core) {
return new FieldMutatingUpdateProcessor.FieldNameSelector() {
@Override
public boolean shouldMutate(final String fieldName) {
final IndexSchema schema = core.getLatestSchema();
FieldType type = schema.getFieldTypeNoEx(fieldName);
return (null == type) || type instanceof DateValueFieldType;
}
return fieldName -> {
final IndexSchema schema = core.getLatestSchema();
FieldType type = schema.getFieldTypeNoEx(fieldName);
return (null == type) || type instanceof DateValueFieldType;
};
}
}

View File

@ -21,6 +21,7 @@ import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.SolrCore;
import org.apache.solr.schema.FieldType;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.update.processor.FieldMutatingUpdateProcessor.FieldNameSelector;
import java.util.Locale;
@ -67,16 +68,11 @@ public abstract class ParseNumericFieldUpdateProcessorFactory extends FieldMutat
* @param core Where to get the current schema from
*/
@Override
public FieldMutatingUpdateProcessor.FieldNameSelector
getDefaultSelector(final SolrCore core) {
return new FieldMutatingUpdateProcessor.FieldNameSelector() {
@Override
public boolean shouldMutate(final String fieldName) {
final IndexSchema schema = core.getLatestSchema();
FieldType type = schema.getFieldTypeNoEx(fieldName);
return (null == type) || isSchemaFieldTypeCompatible(type);
}
public FieldNameSelector getDefaultSelector(final SolrCore core) {
return fieldName -> {
final IndexSchema schema = core.getLatestSchema();
FieldType type = schema.getFieldTypeNoEx(fieldName);
return (null == type) || isSchemaFieldTypeCompatible(type);
};
}
}

View File

@ -16,18 +16,18 @@
*/
package org.apache.solr.update.processor;
import org.apache.solr.core.SolrCore;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.SolrCore;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
import java.util.regex.PatternSyntaxException;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import static org.apache.solr.update.processor.FieldValueMutatingUpdateProcessor.valueMutator;
/**
@ -130,15 +130,12 @@ public final class RegexReplaceProcessorFactory extends FieldMutatingUpdateProce
public UpdateRequestProcessor getInstance(SolrQueryRequest request,
SolrQueryResponse response,
UpdateRequestProcessor next) {
return new FieldValueMutatingUpdateProcessor(getSelector(), next) {
@Override
protected Object mutateValue(final Object src) {
if (src instanceof CharSequence) {
CharSequence txt = (CharSequence)src;
return pattern.matcher(txt).replaceAll(replacement);
}
return src;
return valueMutator(getSelector(), next, src -> {
if (src instanceof CharSequence) {
CharSequence txt = (CharSequence) src;
return pattern.matcher(txt).replaceAll(replacement);
}
};
return src;
});
}
}

View File

@ -20,6 +20,9 @@ import org.apache.solr.common.util.NamedList;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
import static org.apache.solr.update.processor.FieldValueMutatingUpdateProcessor.DELETE_VALUE_SINGLETON;
import static org.apache.solr.update.processor.FieldValueMutatingUpdateProcessor.valueMutator;
/**
* Removes any values found which are CharSequence with a length of 0.
* (ie: empty strings)
@ -54,16 +57,13 @@ public final class RemoveBlankFieldUpdateProcessorFactory extends FieldMutatingU
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
SolrQueryResponse rsp,
UpdateRequestProcessor next) {
return new FieldValueMutatingUpdateProcessor(getSelector(), next) {
@Override
protected Object mutateValue(final Object src) {
if (src instanceof CharSequence
&& 0 == ((CharSequence)src).length()) {
return DELETE_VALUE_SINGLETON;
}
return src;
return valueMutator(getSelector(), next, src -> {
if (src instanceof CharSequence
&& 0 == ((CharSequence) src).length()) {
return DELETE_VALUE_SINGLETON;
}
};
return src;
});
}
}

View File

@ -20,6 +20,8 @@ import org.apache.solr.common.util.NamedList;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
import static org.apache.solr.update.processor.FieldValueMutatingUpdateProcessor.valueMutator;
/**
* Trims leading and trailing whitespace from any CharSequence values
@ -48,20 +50,17 @@ public final class TrimFieldUpdateProcessorFactory extends FieldMutatingUpdatePr
// no trim specific init args
super.init(args);
}
@Override
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
SolrQueryResponse rsp,
UpdateRequestProcessor next) {
return new FieldValueMutatingUpdateProcessor(getSelector(), next) {
@Override
protected Object mutateValue(final Object src) {
if (src instanceof CharSequence) {
return ((CharSequence)src).toString().trim();
}
return src;
return valueMutator(getSelector(), next, src -> {
if (src instanceof CharSequence) {
return src.toString().trim();
}
};
return src;
});
}
}

View File

@ -19,10 +19,13 @@ package org.apache.solr.update.processor;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.SolrCore;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.update.processor.FieldMutatingUpdateProcessor.FieldNameSelector;
import static org.apache.solr.update.processor.FieldMutatingUpdateProcessor.SELECT_NO_FIELDS;
import static org.apache.solr.update.processor.FieldValueMutatingUpdateProcessor.valueMutator;
/**
* Truncates any CharSequence values found in fields matching the specified
@ -75,28 +78,23 @@ public final class TruncateFieldUpdateProcessorFactory
}
@Override
public FieldMutatingUpdateProcessor.FieldNameSelector
getDefaultSelector(final SolrCore core) {
return FieldMutatingUpdateProcessor.SELECT_NO_FIELDS;
public FieldNameSelector getDefaultSelector(final SolrCore core) {
return SELECT_NO_FIELDS;
}
@Override
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
SolrQueryResponse rsp,
UpdateRequestProcessor next) {
return new FieldValueMutatingUpdateProcessor(getSelector(), next) {
@Override
protected Object mutateValue(final Object src) {
if (src instanceof CharSequence) {
CharSequence s = (CharSequence)src;
if (maxLength < s.length()) {
return s.subSequence(0, maxLength);
}
return valueMutator(getSelector(), next, src -> {
if (src instanceof CharSequence) {
CharSequence s = (CharSequence) src;
if (maxLength < s.length()) {
return s.subSequence(0, maxLength);
}
return src;
}
};
return src;
});
}
}

View File

@ -22,6 +22,9 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.solr.core.SolrCore;
import org.apache.solr.update.processor.FieldMutatingUpdateProcessor.FieldNameSelector;
import static org.apache.solr.update.processor.FieldMutatingUpdateProcessor.SELECT_NO_FIELDS;
/**
* Removes duplicate values found in fields matching the specified conditions.
@ -46,10 +49,8 @@ import org.apache.solr.core.SolrCore;
public class UniqFieldsUpdateProcessorFactory extends FieldValueSubsetUpdateProcessorFactory {
@Override
public FieldMutatingUpdateProcessor.FieldNameSelector
getDefaultSelector(final SolrCore core) {
return FieldMutatingUpdateProcessor.SELECT_NO_FIELDS;
public FieldNameSelector getDefaultSelector(SolrCore core) {
return SELECT_NO_FIELDS;
}
@Override