public class DecayFunction extends Object
Used in FunctionsScoreQuery, this function scores based on the relative distance between a field and a target value. It can be used to score fields of Geo-point, Date, Long, and Double types. Correspondingly, the decayParam is divided into three types of parameter settings:
DecayFuncGeoParam, DecayFuncDateParam, and DecayFuncNumericParam. Please choose the corresponding DecayParam according to the field type.
In the param, origin, scale, and offset are used together with decay in the DecayFunction to calculate the score. The origin serves as the reference for scoring, while scale and decay set the standard for score decay (documents at a relative distance of scale from the origin will receive a score equal to decay, and documents within a distance less than offset from the origin will also receive the maximum score of 1).
The scoring functions include EXP, GAUSS, and LINEAR, controlled by DecayFunction.MathFunction. For array-type fields, use MultiValueMode to set the scoring mode; MIN indicates selecting the smallest value in the array as the scoring basis, and so on...
Tips: When using DecayFunction to score a specific field, if a document does not have the corresponding field, it will receive the maximum score of 1. To avoid interference,
it is recommended to set an ExistsQuery type Query in the query of FunctionsScoreQuery to filter out such impacts.
| 限定符和类型 | 类和说明 |
|---|---|
static class |
DecayFunction.Builder |
static class |
DecayFunction.MathFunction |
| 构造器和说明 |
|---|
DecayFunction() |
DecayFunction(String fieldName,
DecayParam decayParam,
DecayFunction.MathFunction mathFunction,
Double decay,
MultiValueMode multiValueMode) |
| 限定符和类型 | 方法和说明 |
|---|---|
Double |
getDecay() |
DecayParam |
getDecayParam() |
String |
getFieldName() |
DecayFunction.MathFunction |
getMathFunction() |
MultiValueMode |
getMultiValueMode() |
static DecayFunction.Builder |
newBuilder() |
void |
setDecay(Double decay) |
void |
setDecayParam(DecayParam decayParam) |
void |
setFieldName(String fieldName) |
void |
setMathFunction(DecayFunction.MathFunction mathFunction) |
void |
setMultiValueMode(MultiValueMode multiValueMode) |
public DecayFunction()
public DecayFunction(String fieldName, DecayParam decayParam, DecayFunction.MathFunction mathFunction, Double decay, MultiValueMode multiValueMode)
public String getFieldName()
public void setFieldName(String fieldName)
public DecayParam getDecayParam()
public void setDecayParam(DecayParam decayParam)
public DecayFunction.MathFunction getMathFunction()
public void setMathFunction(DecayFunction.MathFunction mathFunction)
public Double getDecay()
public void setDecay(Double decay)
public MultiValueMode getMultiValueMode()
public void setMultiValueMode(MultiValueMode multiValueMode)
public static DecayFunction.Builder newBuilder()
Copyright © 2025. All Rights Reserved.