org.apache.lucene.queries.function.valuesource.RangeMapFloatFunction Maven / Gradle / Ivy
/*
* 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.lucene.queries.function.valuesource;
import java.io.IOException;
import java.util.Map;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.queries.function.FunctionValues;
import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.queries.function.docvalues.FloatDocValues;
import org.apache.lucene.search.IndexSearcher;
/**
* RangeMapFloatFunction
implements a map function over another {@link ValueSource}
* whose values fall within min and max inclusive to target.
* Normally Used as an argument to a {@link org.apache.lucene.queries.function.FunctionQuery}
*/
public class RangeMapFloatFunction extends ValueSource {
protected final ValueSource source;
protected final float min;
protected final float max;
protected final ValueSource target;
protected final ValueSource defaultVal;
public RangeMapFloatFunction(ValueSource source, float min, float max, float target, Float def) {
this(
source,
min,
max,
new ConstValueSource(target),
def == null ? null : new ConstValueSource(def));
}
public RangeMapFloatFunction(
ValueSource source, float min, float max, ValueSource target, ValueSource def) {
this.source = source;
this.min = min;
this.max = max;
this.target = target;
this.defaultVal = def;
}
@Override
public String description() {
return "map("
+ source.description()
+ ","
+ min
+ ","
+ max
+ ","
+ target.description()
+ ","
+ (defaultVal == null ? "null" : defaultVal.description())
+ ")";
}
@Override
public FunctionValues getValues(Map