Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.analytics.function.mapping;
import java.util.function.Consumer;
import java.util.function.DoubleConsumer;
import java.util.function.IntConsumer;
import java.util.function.LongConsumer;
import org.apache.solr.analytics.ExpressionFactory.CreatorFunction;
import org.apache.solr.analytics.util.function.BooleanConsumer;
import org.apache.solr.analytics.util.function.FloatConsumer;
import org.apache.solr.analytics.value.AnalyticsValue;
import org.apache.solr.analytics.value.AnalyticsValueStream;
import org.apache.solr.analytics.value.AnalyticsValueStream.AbstractAnalyticsValueStream;
import org.apache.solr.analytics.value.BooleanValue;
import org.apache.solr.analytics.value.BooleanValueStream;
import org.apache.solr.analytics.value.DateValue;
import org.apache.solr.analytics.value.DateValueStream;
import org.apache.solr.analytics.value.DoubleValue;
import org.apache.solr.analytics.value.DoubleValueStream;
import org.apache.solr.analytics.value.FloatValue;
import org.apache.solr.analytics.value.FloatValueStream;
import org.apache.solr.analytics.value.IntValue;
import org.apache.solr.analytics.value.IntValueStream;
import org.apache.solr.analytics.value.LongValue;
import org.apache.solr.analytics.value.LongValueStream;
import org.apache.solr.analytics.value.StringValue;
import org.apache.solr.analytics.value.StringValueStream;
import org.apache.solr.analytics.value.AnalyticsValue.AbstractAnalyticsValue;
import org.apache.solr.analytics.value.BooleanValue.AbstractBooleanValue;
import org.apache.solr.analytics.value.BooleanValueStream.AbstractBooleanValueStream;
import org.apache.solr.analytics.value.DateValue.AbstractDateValue;
import org.apache.solr.analytics.value.DateValueStream.AbstractDateValueStream;
import org.apache.solr.analytics.value.DoubleValue.AbstractDoubleValue;
import org.apache.solr.analytics.value.DoubleValueStream.AbstractDoubleValueStream;
import org.apache.solr.analytics.value.FloatValue.AbstractFloatValue;
import org.apache.solr.analytics.value.FloatValueStream.AbstractFloatValueStream;
import org.apache.solr.analytics.value.IntValue.AbstractIntValue;
import org.apache.solr.analytics.value.IntValueStream.AbstractIntValueStream;
import org.apache.solr.analytics.value.LongValue.AbstractLongValue;
import org.apache.solr.analytics.value.LongValueStream.AbstractLongValueStream;
import org.apache.solr.analytics.value.StringValue.AbstractStringValue;
import org.apache.solr.analytics.value.StringValueStream.AbstractStringValueStream;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
/**
* A mapping function to remove an {@link AnalyticsValue} from an {@link AnalyticsValue} or an {@link AnalyticsValueStream}.
* For each document, the value exists if it doesn't equal the value of the second parameter.
*
* The first parameter can be any type of analytics expression. If the parameter is multi-valued, then the return will be multi-valued. (Required)
*
* The second parameter, which is the value to remove from the first parameter, must be an {@link AnalyticsValue}, aka single-valued. (Required)
*
* The resulting Value or ValueStream will be typed with the closest super-type of the two parameters.
* (e.g. {@value #name}(int,float) will return a float)
*/
public class RemoveFunction {
public static final String name = "remove";
public static final CreatorFunction creatorFunction = (params -> {
if (params.length != 2) {
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires 2 paramaters, " + params.length + " found.");
}
if (!(params[1] instanceof AnalyticsValue)) {
throw new SolrException(ErrorCode.BAD_REQUEST,"The "+name+" function requires the remove (2nd) paramater to be single-valued.");
}
AnalyticsValueStream baseExpr = params[0];
AnalyticsValue removeExpr = (AnalyticsValue)params[1];
if (baseExpr instanceof DateValue && removeExpr instanceof DateValue) {
return new DateRemoveFunction((DateValue)baseExpr,(DateValue)removeExpr);
}
if (baseExpr instanceof DateValueStream && removeExpr instanceof DateValue) {
return new DateStreamRemoveFunction((DateValueStream)baseExpr,(DateValue)removeExpr);
}
if (baseExpr instanceof BooleanValue && removeExpr instanceof BooleanValue) {
return new BooleanRemoveFunction((BooleanValue)baseExpr,(BooleanValue)removeExpr);
}
if (baseExpr instanceof BooleanValueStream && removeExpr instanceof BooleanValue) {
return new BooleanStreamRemoveFunction((BooleanValueStream)baseExpr,(BooleanValue)removeExpr);
}
if (baseExpr instanceof IntValue && removeExpr instanceof IntValue) {
return new IntRemoveFunction((IntValue)baseExpr,(IntValue)removeExpr);
}
if (baseExpr instanceof IntValueStream && removeExpr instanceof IntValue) {
return new IntStreamRemoveFunction((IntValueStream)baseExpr,(IntValue)removeExpr);
}
if (baseExpr instanceof LongValue && removeExpr instanceof LongValue) {
return new LongRemoveFunction((LongValue)baseExpr,(LongValue)removeExpr);
}
if (baseExpr instanceof LongValueStream && removeExpr instanceof LongValue) {
return new LongStreamRemoveFunction((LongValueStream)baseExpr,(LongValue)removeExpr);
}
if (baseExpr instanceof FloatValue && removeExpr instanceof FloatValue) {
return new FloatRemoveFunction((FloatValue)baseExpr,(FloatValue)removeExpr);
}
if (baseExpr instanceof FloatValueStream && removeExpr instanceof FloatValue) {
return new FloatStreamRemoveFunction((FloatValueStream)baseExpr,(FloatValue)removeExpr);
}
if (baseExpr instanceof DoubleValue && removeExpr instanceof DoubleValue) {
return new DoubleRemoveFunction((DoubleValue)baseExpr,(DoubleValue)removeExpr);
}
if (baseExpr instanceof DoubleValueStream && removeExpr instanceof DoubleValue) {
return new DoubleStreamRemoveFunction((DoubleValueStream)baseExpr,(DoubleValue)removeExpr);
}
if (baseExpr instanceof StringValue && removeExpr instanceof StringValue) {
return new StringRemoveFunction((StringValue)baseExpr,(StringValue)removeExpr);
}
if (baseExpr instanceof StringValueStream && removeExpr instanceof StringValue) {
return new StringStreamRemoveFunction((StringValueStream)baseExpr,(StringValue)removeExpr);
}
if (baseExpr instanceof AnalyticsValue) {
return new ValueRemoveFunction((AnalyticsValue)baseExpr,removeExpr);
}
return new StreamRemoveFunction(baseExpr,removeExpr);
});
}
class StreamRemoveFunction extends AbstractAnalyticsValueStream {
private final AnalyticsValueStream baseExpr;
private final AnalyticsValue removeExpr;
public static final String name = RemoveFunction.name;
private final String exprStr;
private final ExpressionType funcType;
public StreamRemoveFunction(AnalyticsValueStream baseExpr, AnalyticsValue removeExpr) throws SolrException {
this.baseExpr = baseExpr;
this.removeExpr = removeExpr;
this.exprStr = AnalyticsValueStream.createExpressionString(name,baseExpr,removeExpr);
this.funcType = AnalyticsValueStream.determineMappingPhase(exprStr,baseExpr,removeExpr);
}
@Override
public void streamObjects(Consumer