org.apache.lucene.queries.function.valuesource.ScaleFloatFunction 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.List;
import java.util.Map;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.ReaderUtil;
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;
/**
* Scales values to be between min and max.
*
* This implementation currently traverses all of the source values to obtain their min and max.
*
*
This implementation currently cannot distinguish when documents have been deleted or documents
* that have no value, and 0.0 values will be used for these cases. This means that if values are
* normally all greater than 0.0, one can still end up with 0.0 as the min value to map from. In
* these cases, an appropriate map() function could be used as a workaround to change 0.0 to a value
* in the real range.
*/
public class ScaleFloatFunction extends ValueSource {
protected final ValueSource source;
protected final float min;
protected final float max;
public ScaleFloatFunction(ValueSource source, float min, float max) {
this.source = source;
this.min = min;
this.max = max;
}
@Override
public String description() {
return "scale(" + source.description() + "," + min + "," + max + ")";
}
private static class ScaleInfo {
float minVal;
float maxVal;
}
private ScaleInfo createScaleInfo(Map