mirror of https://github.com/apache/lucene.git
SOLR-8995: Use lamdas in URPs
This commit is contained in:
parent
d146354457
commit
80336a278a
|
@ -16,6 +16,17 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.solr.update.processor;
|
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.SolrException;
|
||||||
import org.apache.solr.common.SolrInputDocument;
|
import org.apache.solr.common.SolrInputDocument;
|
||||||
import org.apache.solr.common.SolrInputField;
|
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.ManagedIndexSchema;
|
||||||
import org.apache.solr.schema.SchemaField;
|
import org.apache.solr.schema.SchemaField;
|
||||||
import org.apache.solr.update.AddUpdateCommand;
|
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.FieldMutatingUpdateProcessor.FieldNameSelector;
|
||||||
|
import org.apache.solr.update.processor.FieldMutatingUpdateProcessorFactory.SelectorParams;
|
||||||
import org.apache.solr.util.plugin.SolrCoreAware;
|
import org.apache.solr.util.plugin.SolrCoreAware;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
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.BAD_REQUEST;
|
||||||
import static org.apache.solr.common.SolrException.ErrorCode.SERVER_ERROR;
|
import static org.apache.solr.common.SolrException.ErrorCode.SERVER_ERROR;
|
||||||
import static org.apache.solr.core.ConfigSetProperties.IMMUTABLE_CONFIGSET_ARG;
|
import static org.apache.solr.core.ConfigSetProperties.IMMUTABLE_CONFIGSET_ARG;
|
||||||
|
@ -384,18 +384,9 @@ public class AddSchemaFieldsUpdateProcessorFactory extends UpdateRequestProcesso
|
||||||
return defaultFieldType;
|
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) {
|
private FieldNameSelector buildSelector(IndexSchema schema) {
|
||||||
FieldNameSelector selector = FieldMutatingUpdateProcessor.createFieldNameSelector
|
FieldNameSelector selector = FieldMutatingUpdateProcessor.createFieldNameSelector
|
||||||
(solrResourceLoader, schema, inclusions, getDefaultSelector(schema));
|
(solrResourceLoader, schema, inclusions, fieldName -> null == schema.getFieldTypeNoEx(fieldName));
|
||||||
|
|
||||||
for (SelectorParams exc : exclusions) {
|
for (SelectorParams exc : exclusions) {
|
||||||
selector = FieldMutatingUpdateProcessor.wrap(selector, FieldMutatingUpdateProcessor.createFieldNameSelector
|
selector = FieldMutatingUpdateProcessor.wrap(selector, FieldMutatingUpdateProcessor.createFieldNameSelector
|
||||||
|
|
|
@ -16,19 +16,19 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.solr.update.processor;
|
package org.apache.solr.update.processor;
|
||||||
|
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.commons.lang.StringUtils;
|
||||||
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.solr.common.SolrInputField;
|
import org.apache.solr.common.SolrInputField;
|
||||||
import org.apache.solr.common.util.NamedList;
|
import org.apache.solr.common.util.NamedList;
|
||||||
|
import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.solr.request.SolrQueryRequest;
|
import org.apache.solr.request.SolrQueryRequest;
|
||||||
import org.apache.solr.response.SolrQueryResponse;
|
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
|
* Concatenates multiple values for fields matching the specified
|
||||||
|
@ -77,44 +77,38 @@ public final class ConcatFieldUpdateProcessorFactory extends FieldMutatingUpdate
|
||||||
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
|
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
|
||||||
SolrQueryResponse rsp,
|
SolrQueryResponse rsp,
|
||||||
UpdateRequestProcessor next) {
|
UpdateRequestProcessor next) {
|
||||||
return new FieldMutatingUpdateProcessor(getSelector(), next) {
|
return mutator(getSelector(), next, src -> {
|
||||||
@Override
|
if (src.getValueCount() <= 1) return src;
|
||||||
protected SolrInputField mutate(final SolrInputField src) {
|
|
||||||
if (src.getValueCount() <= 1) return src;
|
|
||||||
|
|
||||||
SolrInputField result = new SolrInputField(src.getName());
|
SolrInputField result = new SolrInputField(src.getName());
|
||||||
result.setValue(StringUtils.join(src.getValues(), delimiter),
|
result.setValue(StringUtils.join(src.getValues(), delimiter),
|
||||||
src.getBoost());
|
src.getBoost());
|
||||||
return result;
|
return result;
|
||||||
}
|
});
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldMutatingUpdateProcessor.FieldNameSelector
|
public FieldMutatingUpdateProcessor.FieldNameSelector
|
||||||
getDefaultSelector(final SolrCore core) {
|
getDefaultSelector(final SolrCore core) {
|
||||||
|
|
||||||
return new FieldMutatingUpdateProcessor.FieldNameSelector() {
|
return fieldName -> {
|
||||||
@Override
|
final IndexSchema schema = core.getLatestSchema();
|
||||||
public boolean shouldMutate(final String fieldName) {
|
|
||||||
final IndexSchema schema = core.getLatestSchema();
|
|
||||||
|
|
||||||
// first check type since it should be fastest
|
// first check type since it should be fastest
|
||||||
FieldType type = schema.getFieldTypeNoEx(fieldName);
|
FieldType type = schema.getFieldTypeNoEx(fieldName);
|
||||||
if (null == type) return false;
|
if (null == type) return false;
|
||||||
|
|
||||||
if (! (TextField.class.isInstance(type)
|
|
||||||
|| StrField.class.isInstance(type))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// only ask for SchemaField if we passed the type check.
|
if (! (TextField.class.isInstance(type)
|
||||||
SchemaField sf = schema.getFieldOrNull(fieldName);
|
|| StrField.class.isInstance(type))) {
|
||||||
// shouldn't be null since since type wasn't, but just in case
|
return false;
|
||||||
if (null == sf) return false;
|
|
||||||
|
|
||||||
return ! sf.multiValued();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@ import org.apache.solr.common.SolrInputField;
|
||||||
import org.apache.solr.request.SolrQueryRequest;
|
import org.apache.solr.request.SolrQueryRequest;
|
||||||
import org.apache.solr.response.SolrQueryResponse;
|
import org.apache.solr.response.SolrQueryResponse;
|
||||||
|
|
||||||
|
import static org.apache.solr.update.processor.FieldMutatingUpdateProcessor.mutator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Replaces any list of values for a field matching the specified
|
* 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,
|
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
|
||||||
SolrQueryResponse rsp,
|
SolrQueryResponse rsp,
|
||||||
UpdateRequestProcessor next) {
|
UpdateRequestProcessor next) {
|
||||||
return new FieldMutatingUpdateProcessor(getSelector(), next) {
|
return mutator(getSelector(), next, src -> {
|
||||||
@Override
|
SolrInputField result = new SolrInputField(src.getName());
|
||||||
protected SolrInputField mutate(final SolrInputField src) {
|
result.setValue(src.getValueCount(),
|
||||||
SolrInputField result = new SolrInputField(src.getName());
|
src.getBoost());
|
||||||
result.setValue(src.getValueCount(),
|
return result;
|
||||||
src.getBoost());
|
});
|
||||||
return result;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,13 @@
|
||||||
package org.apache.solr.update.processor;
|
package org.apache.solr.update.processor;
|
||||||
|
|
||||||
import org.apache.solr.common.util.NamedList;
|
import org.apache.solr.common.util.NamedList;
|
||||||
|
import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.solr.request.SolrQueryRequest;
|
import org.apache.solr.request.SolrQueryRequest;
|
||||||
import org.apache.solr.response.SolrQueryResponse;
|
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
|
@Override
|
||||||
public FieldMutatingUpdateProcessor.FieldNameSelector
|
public FieldNameSelector getDefaultSelector(final SolrCore core) {
|
||||||
getDefaultSelector(final SolrCore core) {
|
return SELECT_NO_FIELDS;
|
||||||
|
|
||||||
return FieldMutatingUpdateProcessor.SELECT_NO_FIELDS;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
|
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
|
||||||
SolrQueryResponse rsp,
|
SolrQueryResponse rsp,
|
||||||
UpdateRequestProcessor next) {
|
UpdateRequestProcessor next) {
|
||||||
return new FieldValueMutatingUpdateProcessor(getSelector(), next) {
|
return valueMutator(getSelector(), next, src -> {
|
||||||
@Override
|
if (src instanceof CharSequence) {
|
||||||
protected Object mutateValue(final Object src) {
|
return ((CharSequence) src).length();
|
||||||
if (src instanceof CharSequence) {
|
|
||||||
return new Integer(((CharSequence)src).length());
|
|
||||||
}
|
|
||||||
return src;
|
|
||||||
}
|
}
|
||||||
};
|
return src;
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,15 +20,12 @@ import java.io.IOException;
|
||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import static org.apache.solr.common.SolrException.ErrorCode.BAD_REQUEST;
|
import org.apache.solr.common.SolrException;
|
||||||
import static org.apache.solr.common.SolrException.ErrorCode.SERVER_ERROR;
|
|
||||||
import static org.apache.solr.update.processor.FieldMutatingUpdateProcessorFactory.SelectorParams;
|
|
||||||
|
|
||||||
import org.apache.solr.common.SolrInputDocument;
|
import org.apache.solr.common.SolrInputDocument;
|
||||||
import org.apache.solr.common.SolrInputField;
|
import org.apache.solr.common.SolrInputField;
|
||||||
import org.apache.solr.common.SolrException;
|
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.solr.core.SolrResourceLoader;
|
import org.apache.solr.core.SolrResourceLoader;
|
||||||
import org.apache.solr.schema.FieldType;
|
import org.apache.solr.schema.FieldType;
|
||||||
|
@ -37,6 +34,10 @@ import org.apache.solr.update.AddUpdateCommand;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
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
|
* Reusable base class for UpdateProcessors that will consider
|
||||||
* AddUpdateCommands and mutate the values associated with configured
|
* AddUpdateCommands and mutate the values associated with configured
|
||||||
|
@ -120,27 +121,15 @@ public abstract class FieldMutatingUpdateProcessor
|
||||||
/**
|
/**
|
||||||
* Interface for identifying which fields should be mutated
|
* Interface for identifying which fields should be mutated
|
||||||
*/
|
*/
|
||||||
public static interface FieldNameSelector {
|
public interface FieldNameSelector {
|
||||||
public boolean shouldMutate(final String fieldName);
|
boolean shouldMutate(final String fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Singleton indicating all fields should be mutated */
|
/** Singleton indicating all fields should be mutated */
|
||||||
public static final FieldNameSelector SELECT_ALL_FIELDS
|
public static final FieldNameSelector SELECT_ALL_FIELDS = fieldName -> true;
|
||||||
= new FieldNameSelector() {
|
|
||||||
@Override
|
|
||||||
public boolean shouldMutate(final String fieldName) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Singleton indicating no fields should be mutated */
|
/** Singleton indicating no fields should be mutated */
|
||||||
public static final FieldNameSelector SELECT_NO_FIELDS
|
public static final FieldNameSelector SELECT_NO_FIELDS = fieldName -> false;
|
||||||
= new FieldNameSelector() {
|
|
||||||
@Override
|
|
||||||
public boolean shouldMutate(final String fieldName) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps two FieldNameSelectors such that the FieldNameSelector
|
* Wraps two FieldNameSelectors such that the FieldNameSelector
|
||||||
|
@ -165,21 +154,11 @@ public abstract class FieldMutatingUpdateProcessor
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SELECT_ALL_FIELDS == includes) {
|
if (SELECT_ALL_FIELDS == includes) {
|
||||||
return new FieldNameSelector() {
|
return fieldName -> ! excludes.shouldMutate(fieldName);
|
||||||
@Override
|
|
||||||
public boolean shouldMutate(final String fieldName) {
|
|
||||||
return ! excludes.shouldMutate(fieldName);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new FieldNameSelector() {
|
return fieldName -> (includes.shouldMutate(fieldName)
|
||||||
@Override
|
&& ! excludes.shouldMutate(fieldName));
|
||||||
public boolean shouldMutate(final String fieldName) {
|
|
||||||
return (includes.shouldMutate(fieldName)
|
|
||||||
&& ! excludes.shouldMutate(fieldName));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -201,12 +180,7 @@ public abstract class FieldMutatingUpdateProcessor
|
||||||
|
|
||||||
final ConfigurableFieldNameSelectorHelper helper =
|
final ConfigurableFieldNameSelectorHelper helper =
|
||||||
new ConfigurableFieldNameSelectorHelper(loader, params);
|
new ConfigurableFieldNameSelectorHelper(loader, params);
|
||||||
return new FieldNameSelector() {
|
return fieldName -> helper.shouldMutateBasedOnSchema(fieldName, core.getLatestSchema());
|
||||||
@Override
|
|
||||||
public boolean shouldMutate(String fieldName) {
|
|
||||||
return helper.shouldMutateBasedOnSchema(fieldName, core.getLatestSchema());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -229,12 +203,7 @@ public abstract class FieldMutatingUpdateProcessor
|
||||||
|
|
||||||
final ConfigurableFieldNameSelectorHelper helper =
|
final ConfigurableFieldNameSelectorHelper helper =
|
||||||
new ConfigurableFieldNameSelectorHelper(loader, params);
|
new ConfigurableFieldNameSelectorHelper(loader, params);
|
||||||
return new FieldNameSelector() {
|
return fieldName -> helper.shouldMutateBasedOnSchema(fieldName, schema);
|
||||||
@Override
|
|
||||||
public boolean shouldMutate(String fieldName) {
|
|
||||||
return helper.shouldMutateBasedOnSchema(fieldName, schema);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class ConfigurableFieldNameSelectorHelper {
|
private static final class ConfigurableFieldNameSelectorHelper {
|
||||||
|
@ -317,5 +286,16 @@ public abstract class FieldMutatingUpdateProcessor
|
||||||
return false;
|
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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,11 @@ import java.util.regex.PatternSyntaxException;
|
||||||
import org.apache.solr.common.SolrException;
|
import org.apache.solr.common.SolrException;
|
||||||
import org.apache.solr.common.util.NamedList;
|
import org.apache.solr.common.util.NamedList;
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
|
import org.apache.solr.update.processor.FieldMutatingUpdateProcessor.FieldNameSelector;
|
||||||
import org.apache.solr.util.plugin.SolrCoreAware;
|
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
|
* Base class for implementing Factories for FieldMutatingUpdateProcessors and
|
||||||
|
@ -101,7 +104,7 @@ import org.apache.solr.util.plugin.SolrCoreAware;
|
||||||
*
|
*
|
||||||
* @see FieldMutatingUpdateProcessor
|
* @see FieldMutatingUpdateProcessor
|
||||||
* @see FieldValueMutatingUpdateProcessor
|
* @see FieldValueMutatingUpdateProcessor
|
||||||
* @see FieldMutatingUpdateProcessor.FieldNameSelector
|
* @see FieldNameSelector
|
||||||
*/
|
*/
|
||||||
public abstract class FieldMutatingUpdateProcessorFactory
|
public abstract class FieldMutatingUpdateProcessorFactory
|
||||||
extends UpdateRequestProcessorFactory
|
extends UpdateRequestProcessorFactory
|
||||||
|
@ -125,9 +128,9 @@ public abstract class FieldMutatingUpdateProcessorFactory
|
||||||
private Collection<SelectorParams> exclusions
|
private Collection<SelectorParams> exclusions
|
||||||
= new ArrayList<>();
|
= 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;
|
if (null != selector) return selector;
|
||||||
|
|
||||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
|
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
|
||||||
|
@ -234,10 +237,7 @@ public abstract class FieldMutatingUpdateProcessorFactory
|
||||||
*
|
*
|
||||||
* @see FieldMutatingUpdateProcessor#SELECT_ALL_FIELDS
|
* @see FieldMutatingUpdateProcessor#SELECT_ALL_FIELDS
|
||||||
*/
|
*/
|
||||||
protected FieldMutatingUpdateProcessor.FieldNameSelector
|
protected FieldNameSelector getDefaultSelector(SolrCore core) {
|
||||||
getDefaultSelector(final SolrCore core) {
|
return SELECT_ALL_FIELDS;
|
||||||
|
|
||||||
return FieldMutatingUpdateProcessor.SELECT_ALL_FIELDS;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.solr.update.processor;
|
||||||
|
|
||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
import org.apache.solr.common.SolrInputField;
|
import org.apache.solr.common.SolrInputField;
|
||||||
|
|
||||||
|
@ -83,5 +84,16 @@ public abstract class FieldValueMutatingUpdateProcessor
|
||||||
result.setBoost(src.getBoost());
|
result.setBoost(src.getBoost());
|
||||||
return 0 == result.getValueCount() ? null : result;
|
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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,11 +16,13 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.solr.update.processor;
|
package org.apache.solr.update.processor;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.apache.solr.common.SolrInputField;
|
import org.apache.solr.common.SolrInputField;
|
||||||
import org.apache.solr.request.SolrQueryRequest;
|
import org.apache.solr.request.SolrQueryRequest;
|
||||||
import org.apache.solr.response.SolrQueryResponse;
|
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
|
* 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,
|
public final UpdateRequestProcessor getInstance(SolrQueryRequest req,
|
||||||
SolrQueryResponse rsp,
|
SolrQueryResponse rsp,
|
||||||
UpdateRequestProcessor next) {
|
UpdateRequestProcessor next) {
|
||||||
return new FieldMutatingUpdateProcessor(getSelector(), next) {
|
return mutator(getSelector(), next, src -> {
|
||||||
@Override
|
if (src.getValueCount() <= 1) return src;
|
||||||
protected SolrInputField mutate(final SolrInputField src) {
|
|
||||||
if (src.getValueCount() <= 1) return src;
|
|
||||||
|
|
||||||
SolrInputField result = new SolrInputField(src.getName());
|
SolrInputField result = new SolrInputField(src.getName());
|
||||||
result.setValue(pickSubset(src.getValues()),
|
result.setValue(pickSubset(src.getValues()),
|
||||||
src.getBoost());
|
src.getBoost());
|
||||||
return result;
|
return result;
|
||||||
}
|
});
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,10 +16,13 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.solr.update.processor;
|
package org.apache.solr.update.processor;
|
||||||
|
|
||||||
import org.apache.solr.core.SolrCore;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Collection;
|
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
|
* Keeps only the first value of fields matching the specified
|
||||||
|
@ -53,10 +56,8 @@ public final class FirstFieldValueUpdateProcessorFactory extends FieldValueSubse
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldMutatingUpdateProcessor.FieldNameSelector
|
public FieldNameSelector getDefaultSelector(SolrCore core) {
|
||||||
getDefaultSelector(final SolrCore core) {
|
return SELECT_NO_FIELDS;
|
||||||
|
|
||||||
return FieldMutatingUpdateProcessor.SELECT_NO_FIELDS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,18 +16,19 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.solr.update.processor;
|
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.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.io.StringWriter;
|
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
|
* Strips all HTML Markup in any CharSequence values
|
||||||
* found in fields matching the specified conditions.
|
* found in fields matching the specified conditions.
|
||||||
|
@ -58,29 +59,25 @@ public final class HTMLStripFieldUpdateProcessorFactory extends FieldMutatingUpd
|
||||||
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
|
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
|
||||||
SolrQueryResponse rsp,
|
SolrQueryResponse rsp,
|
||||||
UpdateRequestProcessor next) {
|
UpdateRequestProcessor next) {
|
||||||
return new FieldValueMutatingUpdateProcessor(getSelector(), next) {
|
return valueMutator(getSelector(), next, src -> {
|
||||||
@Override
|
if (src instanceof CharSequence) {
|
||||||
protected Object mutateValue(final Object src) {
|
CharSequence s = (CharSequence) src;
|
||||||
if (src instanceof CharSequence) {
|
StringWriter result = new StringWriter(s.length());
|
||||||
CharSequence s = (CharSequence)src;
|
Reader in = null;
|
||||||
StringWriter result = new StringWriter(s.length());
|
try {
|
||||||
Reader in = null;
|
in = new HTMLStripCharFilter
|
||||||
try {
|
|
||||||
in = new HTMLStripCharFilter
|
|
||||||
(new StringReader(s.toString()));
|
(new StringReader(s.toString()));
|
||||||
IOUtils.copy(in, result);
|
IOUtils.copy(in, result);
|
||||||
return result.toString();
|
return result.toString();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// we tried and failed
|
// we tried and failed
|
||||||
return s;
|
return s;
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(in);
|
IOUtils.closeQuietly(in);
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return src;
|
|
||||||
}
|
}
|
||||||
};
|
return src;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,12 +17,13 @@
|
||||||
package org.apache.solr.update.processor;
|
package org.apache.solr.update.processor;
|
||||||
|
|
||||||
import org.apache.solr.core.SolrCore;
|
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.request.SolrQueryRequest;
|
||||||
import org.apache.solr.response.SolrQueryResponse;
|
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 & removes fields matching the specified
|
* Ignores & removes fields matching the specified
|
||||||
|
@ -57,26 +58,16 @@ public final class IgnoreFieldUpdateProcessorFactory extends FieldMutatingUpdate
|
||||||
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
|
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
|
||||||
SolrQueryResponse rsp,
|
SolrQueryResponse rsp,
|
||||||
UpdateRequestProcessor next) {
|
UpdateRequestProcessor next) {
|
||||||
return new FieldMutatingUpdateProcessor(getSelector(), next) {
|
return mutator(getSelector(), next, src -> null);
|
||||||
@Override
|
|
||||||
protected SolrInputField mutate(final SolrInputField src) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldMutatingUpdateProcessor.FieldNameSelector
|
public FieldNameSelector getDefaultSelector(final SolrCore core) {
|
||||||
getDefaultSelector(final SolrCore core) {
|
return fieldName -> {
|
||||||
|
final IndexSchema schema = core.getLatestSchema();
|
||||||
return new FieldMutatingUpdateProcessor.FieldNameSelector() {
|
FieldType type = schema.getFieldTypeNoEx(fieldName);
|
||||||
@Override
|
return (null == type);
|
||||||
public boolean shouldMutate(final String fieldName) {
|
|
||||||
final IndexSchema schema = core.getLatestSchema();
|
|
||||||
FieldType type = schema.getFieldTypeNoEx(fieldName);
|
|
||||||
return (null == type);
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,12 +17,15 @@
|
||||||
package org.apache.solr.update.processor;
|
package org.apache.solr.update.processor;
|
||||||
|
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
|
import org.apache.solr.update.processor.FieldMutatingUpdateProcessor.FieldNameSelector;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.SortedSet;
|
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
|
* Keeps only the last value of fields matching the specified
|
||||||
* conditions. Correct behavior assumes that the SolrInputFields being mutated
|
* conditions. Correct behavior assumes that the SolrInputFields being mutated
|
||||||
|
@ -69,10 +72,8 @@ public final class LastFieldValueUpdateProcessorFactory extends FieldValueSubset
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldMutatingUpdateProcessor.FieldNameSelector
|
public FieldNameSelector getDefaultSelector(final SolrCore core) {
|
||||||
getDefaultSelector(final SolrCore core) {
|
return SELECT_NO_FIELDS;
|
||||||
|
|
||||||
return FieldMutatingUpdateProcessor.SELECT_NO_FIELDS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,14 +16,15 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.solr.update.processor;
|
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.common.SolrException;
|
||||||
|
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
|
import org.apache.solr.update.processor.FieldMutatingUpdateProcessor.FieldNameSelector;
|
||||||
|
|
||||||
import java.util.Collections;
|
import static org.apache.solr.common.SolrException.ErrorCode.BAD_REQUEST;
|
||||||
import java.util.Collection;
|
import static org.apache.solr.update.processor.FieldMutatingUpdateProcessor.SELECT_NO_FIELDS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An update processor that keeps only the the maximum value from any selected
|
* An update processor that keeps only the the maximum value from any selected
|
||||||
|
@ -59,7 +60,7 @@ public final class MaxFieldValueUpdateProcessorFactory extends FieldValueSubsetU
|
||||||
try {
|
try {
|
||||||
// NOTE: the extra cast to Object is needed to prevent compile
|
// NOTE: the extra cast to Object is needed to prevent compile
|
||||||
// errors on Eclipse Compiler (ecj) used for javadoc lint
|
// 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) {
|
} catch (ClassCastException e) {
|
||||||
throw new SolrException
|
throw new SolrException
|
||||||
(BAD_REQUEST,
|
(BAD_REQUEST,
|
||||||
|
@ -69,10 +70,8 @@ public final class MaxFieldValueUpdateProcessorFactory extends FieldValueSubsetU
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldMutatingUpdateProcessor.FieldNameSelector
|
public FieldNameSelector getDefaultSelector(SolrCore core) {
|
||||||
getDefaultSelector(final SolrCore core) {
|
return SELECT_NO_FIELDS;
|
||||||
|
|
||||||
return FieldMutatingUpdateProcessor.SELECT_NO_FIELDS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,14 +16,15 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.solr.update.processor;
|
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.common.SolrException;
|
||||||
|
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
|
import org.apache.solr.update.processor.FieldMutatingUpdateProcessor.FieldNameSelector;
|
||||||
|
|
||||||
import java.util.Collections;
|
import static org.apache.solr.common.SolrException.ErrorCode.BAD_REQUEST;
|
||||||
import java.util.Collection;
|
import static org.apache.solr.update.processor.FieldMutatingUpdateProcessor.SELECT_NO_FIELDS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An update processor that keeps only the the minimum value from any selected
|
* An update processor that keeps only the the minimum value from any selected
|
||||||
|
@ -59,7 +60,7 @@ public final class MinFieldValueUpdateProcessorFactory extends FieldValueSubsetU
|
||||||
try {
|
try {
|
||||||
// NOTE: the extra cast to Object is needed to prevent compile
|
// NOTE: the extra cast to Object is needed to prevent compile
|
||||||
// errors on Eclipse Compiler (ecj) used for javadoc lint
|
// 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) {
|
} catch (ClassCastException e) {
|
||||||
throw new SolrException
|
throw new SolrException
|
||||||
(BAD_REQUEST,
|
(BAD_REQUEST,
|
||||||
|
@ -69,10 +70,8 @@ public final class MinFieldValueUpdateProcessorFactory extends FieldValueSubsetU
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldMutatingUpdateProcessor.FieldNameSelector
|
public FieldNameSelector getDefaultSelector(SolrCore core) {
|
||||||
getDefaultSelector(final SolrCore core) {
|
return SELECT_NO_FIELDS;
|
||||||
|
|
||||||
return FieldMutatingUpdateProcessor.SELECT_NO_FIELDS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,13 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.solr.update.processor;
|
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;
|
||||||
import org.apache.solr.common.SolrException.ErrorCode;
|
import org.apache.solr.common.SolrException.ErrorCode;
|
||||||
import org.apache.solr.common.util.NamedList;
|
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.BoolField;
|
||||||
import org.apache.solr.schema.FieldType;
|
import org.apache.solr.schema.FieldType;
|
||||||
import org.apache.solr.schema.IndexSchema;
|
import org.apache.solr.schema.IndexSchema;
|
||||||
|
import org.apache.solr.update.processor.FieldMutatingUpdateProcessor.FieldNameSelector;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -141,16 +143,11 @@ public class ParseBooleanFieldUpdateProcessorFactory extends FieldMutatingUpdate
|
||||||
* or if the matched field's type is BoolField
|
* or if the matched field's type is BoolField
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public FieldMutatingUpdateProcessor.FieldNameSelector
|
public FieldNameSelector getDefaultSelector(final SolrCore core) {
|
||||||
getDefaultSelector(final SolrCore core) {
|
return fieldName -> {
|
||||||
|
final IndexSchema schema = core.getLatestSchema();
|
||||||
return new FieldMutatingUpdateProcessor.FieldNameSelector() {
|
FieldType type = schema.getFieldTypeNoEx(fieldName);
|
||||||
@Override
|
return (null == type) || (type instanceof BoolField);
|
||||||
public boolean shouldMutate(final String fieldName) {
|
|
||||||
final IndexSchema schema = core.getLatestSchema();
|
|
||||||
FieldType type = schema.getFieldTypeNoEx(fieldName);
|
|
||||||
return (null == type) || (type instanceof BoolField);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,13 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.solr.update.processor;
|
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.commons.lang.LocaleUtils;
|
||||||
import org.apache.solr.common.util.NamedList;
|
import org.apache.solr.common.util.NamedList;
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
|
@ -31,13 +38,6 @@ import org.joda.time.format.DateTimeFormatter;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
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>
|
* <p>
|
||||||
* Attempts to mutate selected fields that have only CharSequence-typed values
|
* Attempts to mutate selected fields that have only CharSequence-typed values
|
||||||
|
@ -165,13 +165,10 @@ public class ParseDateFieldUpdateProcessorFactory extends FieldMutatingUpdatePro
|
||||||
public FieldMutatingUpdateProcessor.FieldNameSelector
|
public FieldMutatingUpdateProcessor.FieldNameSelector
|
||||||
getDefaultSelector(final SolrCore core) {
|
getDefaultSelector(final SolrCore core) {
|
||||||
|
|
||||||
return new FieldMutatingUpdateProcessor.FieldNameSelector() {
|
return fieldName -> {
|
||||||
@Override
|
final IndexSchema schema = core.getLatestSchema();
|
||||||
public boolean shouldMutate(final String fieldName) {
|
FieldType type = schema.getFieldTypeNoEx(fieldName);
|
||||||
final IndexSchema schema = core.getLatestSchema();
|
return (null == type) || type instanceof DateValueFieldType;
|
||||||
FieldType type = schema.getFieldTypeNoEx(fieldName);
|
|
||||||
return (null == type) || type instanceof DateValueFieldType;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import org.apache.solr.common.util.NamedList;
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.solr.schema.FieldType;
|
import org.apache.solr.schema.FieldType;
|
||||||
import org.apache.solr.schema.IndexSchema;
|
import org.apache.solr.schema.IndexSchema;
|
||||||
|
import org.apache.solr.update.processor.FieldMutatingUpdateProcessor.FieldNameSelector;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
@ -67,16 +68,11 @@ public abstract class ParseNumericFieldUpdateProcessorFactory extends FieldMutat
|
||||||
* @param core Where to get the current schema from
|
* @param core Where to get the current schema from
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public FieldMutatingUpdateProcessor.FieldNameSelector
|
public FieldNameSelector getDefaultSelector(final SolrCore core) {
|
||||||
getDefaultSelector(final SolrCore core) {
|
return fieldName -> {
|
||||||
|
final IndexSchema schema = core.getLatestSchema();
|
||||||
return new FieldMutatingUpdateProcessor.FieldNameSelector() {
|
FieldType type = schema.getFieldTypeNoEx(fieldName);
|
||||||
@Override
|
return (null == type) || isSchemaFieldTypeCompatible(type);
|
||||||
public boolean shouldMutate(final String fieldName) {
|
|
||||||
final IndexSchema schema = core.getLatestSchema();
|
|
||||||
FieldType type = schema.getFieldTypeNoEx(fieldName);
|
|
||||||
return (null == type) || isSchemaFieldTypeCompatible(type);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,18 +16,18 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.solr.update.processor;
|
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;
|
||||||
import org.apache.solr.common.SolrException.ErrorCode;
|
import org.apache.solr.common.SolrException.ErrorCode;
|
||||||
import org.apache.solr.common.util.NamedList;
|
import org.apache.solr.common.util.NamedList;
|
||||||
|
import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.solr.request.SolrQueryRequest;
|
import org.apache.solr.request.SolrQueryRequest;
|
||||||
import org.apache.solr.response.SolrQueryResponse;
|
import org.apache.solr.response.SolrQueryResponse;
|
||||||
|
|
||||||
import java.util.regex.PatternSyntaxException;
|
import static org.apache.solr.update.processor.FieldValueMutatingUpdateProcessor.valueMutator;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -130,15 +130,12 @@ public final class RegexReplaceProcessorFactory extends FieldMutatingUpdateProce
|
||||||
public UpdateRequestProcessor getInstance(SolrQueryRequest request,
|
public UpdateRequestProcessor getInstance(SolrQueryRequest request,
|
||||||
SolrQueryResponse response,
|
SolrQueryResponse response,
|
||||||
UpdateRequestProcessor next) {
|
UpdateRequestProcessor next) {
|
||||||
return new FieldValueMutatingUpdateProcessor(getSelector(), next) {
|
return valueMutator(getSelector(), next, src -> {
|
||||||
@Override
|
if (src instanceof CharSequence) {
|
||||||
protected Object mutateValue(final Object src) {
|
CharSequence txt = (CharSequence) src;
|
||||||
if (src instanceof CharSequence) {
|
return pattern.matcher(txt).replaceAll(replacement);
|
||||||
CharSequence txt = (CharSequence)src;
|
|
||||||
return pattern.matcher(txt).replaceAll(replacement);
|
|
||||||
}
|
|
||||||
return src;
|
|
||||||
}
|
}
|
||||||
};
|
return src;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,9 @@ import org.apache.solr.common.util.NamedList;
|
||||||
import org.apache.solr.request.SolrQueryRequest;
|
import org.apache.solr.request.SolrQueryRequest;
|
||||||
import org.apache.solr.response.SolrQueryResponse;
|
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.
|
* Removes any values found which are CharSequence with a length of 0.
|
||||||
* (ie: empty strings)
|
* (ie: empty strings)
|
||||||
|
@ -54,16 +57,13 @@ public final class RemoveBlankFieldUpdateProcessorFactory extends FieldMutatingU
|
||||||
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
|
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
|
||||||
SolrQueryResponse rsp,
|
SolrQueryResponse rsp,
|
||||||
UpdateRequestProcessor next) {
|
UpdateRequestProcessor next) {
|
||||||
return new FieldValueMutatingUpdateProcessor(getSelector(), next) {
|
return valueMutator(getSelector(), next, src -> {
|
||||||
@Override
|
if (src instanceof CharSequence
|
||||||
protected Object mutateValue(final Object src) {
|
&& 0 == ((CharSequence) src).length()) {
|
||||||
if (src instanceof CharSequence
|
return DELETE_VALUE_SINGLETON;
|
||||||
&& 0 == ((CharSequence)src).length()) {
|
|
||||||
return DELETE_VALUE_SINGLETON;
|
|
||||||
}
|
|
||||||
return src;
|
|
||||||
}
|
}
|
||||||
};
|
return src;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@ import org.apache.solr.common.util.NamedList;
|
||||||
import org.apache.solr.request.SolrQueryRequest;
|
import org.apache.solr.request.SolrQueryRequest;
|
||||||
import org.apache.solr.response.SolrQueryResponse;
|
import org.apache.solr.response.SolrQueryResponse;
|
||||||
|
|
||||||
|
import static org.apache.solr.update.processor.FieldValueMutatingUpdateProcessor.valueMutator;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trims leading and trailing whitespace from any CharSequence values
|
* Trims leading and trailing whitespace from any CharSequence values
|
||||||
|
@ -48,20 +50,17 @@ public final class TrimFieldUpdateProcessorFactory extends FieldMutatingUpdatePr
|
||||||
// no trim specific init args
|
// no trim specific init args
|
||||||
super.init(args);
|
super.init(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
|
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
|
||||||
SolrQueryResponse rsp,
|
SolrQueryResponse rsp,
|
||||||
UpdateRequestProcessor next) {
|
UpdateRequestProcessor next) {
|
||||||
return new FieldValueMutatingUpdateProcessor(getSelector(), next) {
|
return valueMutator(getSelector(), next, src -> {
|
||||||
@Override
|
if (src instanceof CharSequence) {
|
||||||
protected Object mutateValue(final Object src) {
|
return src.toString().trim();
|
||||||
if (src instanceof CharSequence) {
|
|
||||||
return ((CharSequence)src).toString().trim();
|
|
||||||
}
|
|
||||||
return src;
|
|
||||||
}
|
}
|
||||||
};
|
return src;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,10 +19,13 @@ package org.apache.solr.update.processor;
|
||||||
import org.apache.solr.common.SolrException;
|
import org.apache.solr.common.SolrException;
|
||||||
import org.apache.solr.common.SolrException.ErrorCode;
|
import org.apache.solr.common.SolrException.ErrorCode;
|
||||||
import org.apache.solr.common.util.NamedList;
|
import org.apache.solr.common.util.NamedList;
|
||||||
|
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.solr.request.SolrQueryRequest;
|
import org.apache.solr.request.SolrQueryRequest;
|
||||||
import org.apache.solr.response.SolrQueryResponse;
|
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
|
* Truncates any CharSequence values found in fields matching the specified
|
||||||
|
@ -75,28 +78,23 @@ public final class TruncateFieldUpdateProcessorFactory
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldMutatingUpdateProcessor.FieldNameSelector
|
public FieldNameSelector getDefaultSelector(final SolrCore core) {
|
||||||
getDefaultSelector(final SolrCore core) {
|
return SELECT_NO_FIELDS;
|
||||||
|
|
||||||
return FieldMutatingUpdateProcessor.SELECT_NO_FIELDS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
|
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
|
||||||
SolrQueryResponse rsp,
|
SolrQueryResponse rsp,
|
||||||
UpdateRequestProcessor next) {
|
UpdateRequestProcessor next) {
|
||||||
return new FieldValueMutatingUpdateProcessor(getSelector(), next) {
|
return valueMutator(getSelector(), next, src -> {
|
||||||
@Override
|
if (src instanceof CharSequence) {
|
||||||
protected Object mutateValue(final Object src) {
|
CharSequence s = (CharSequence) src;
|
||||||
if (src instanceof CharSequence) {
|
if (maxLength < s.length()) {
|
||||||
CharSequence s = (CharSequence)src;
|
return s.subSequence(0, maxLength);
|
||||||
if (maxLength < s.length()) {
|
|
||||||
return s.subSequence(0, maxLength);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return src;
|
|
||||||
}
|
}
|
||||||
};
|
return src;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,9 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.apache.solr.core.SolrCore;
|
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.
|
* 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 {
|
public class UniqFieldsUpdateProcessorFactory extends FieldValueSubsetUpdateProcessorFactory {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldMutatingUpdateProcessor.FieldNameSelector
|
public FieldNameSelector getDefaultSelector(SolrCore core) {
|
||||||
getDefaultSelector(final SolrCore core) {
|
return SELECT_NO_FIELDS;
|
||||||
|
|
||||||
return FieldMutatingUpdateProcessor.SELECT_NO_FIELDS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue