Feature functions
Feature functions can be used in sort expressions. Most are supported only in fine sort expressions. You can combine various syntax and statements to create powerful sorting features.
You must create an index or a property for any document field that is used as a parameter in a feature function. For more information, see the documentation for that function.
normalize: Normalizes a value to the [0, 1] range
1. Overview:
During relevance calculation, a document's quality is measured across different dimensions. Each dimension can have a different score range. For example, page clicks can be in the tens of millions, while text relevance scores are in the [0, 1] range. These scores are not directly comparable. To use these elements in a formula, you must normalize the different scores to the same range. The normalize function provides a simple method for this normalization. The normalize function supports three normalization methods: linear function, logarithmic function, and arctangent function. The function automatically selects a method based on the input parameters. If you specify only the value parameter, normalize uses the arctangent function. If you specify the value and max parameters, normalize uses the logarithmic function. If you specify the value, max, and min parameters, normalize uses the linear function.
2. Usage:
normalize(value, max, min)
3. Parameters:
value: The value to normalize. This parameter supports double-precision floating-point numbers. The value can be retrieved from a document field or another expression.
max: The maximum value of the input. This parameter is optional and supports double-precision floating-point numbers.
min: The minimum value of the input. This parameter is optional and supports double-precision floating-point numbers.
4. Return value:
A double value in the [0, 1] range.
5. Scenarios:
Scenario 1: To normalize the price field when its value range is unknown, use the following formula: normalize(price)
Scenario 2: To normalize the price field when you only know its maximum value is 100, use the following formula: normalize(price, 100)
Scenario 3: To normalize the price field when you know its maximum value is 100 and its minimum value is 1, use the following formula: normalize(price, 100, 1)
Scenario 4: To normalize the result of the distance function to the [0, 1] range: normalize(distance(longitude_in_doc, latitude_in_doc, longitude_in_query, latitude_in_query))
6. Notes:
You must create the function parameters as properties.
When you use the arctangent function for normalization, the normalized value is 0 if value is less than 0.
When you use the logarithmic function for normalization, max must be greater than 1.
When you use the linear function for normalization, max must be greater than min.