Basic sorting is a preliminary screening stage. It quickly finds high-quality documents in the retrieval results and takes the top N results, which are then scored precisely by business sorting. The best results are finally returned to the user. Therefore, basic sorting has a relatively large impact on performance, whereas business sorting has a relatively large impact on the final sorting effect. For this reason, basic sorting should be as simple and effective as possible and should extract only the key factors used in business sorting. Both basic sorting and business sorting are currently configured by using sort expressions. This topic describes the ranking feature functions supported in basic sorting.
Ranking feature functions
static_bm25: static text relevance, used to measure how well a query matches a document
-
Usage: static_bm25()
-
Parameters: none
-
Return value: float. Value range: [0,1].
-
Scenario 1: Specify the text score in a basic sort expression. Set the expression to static_bm25().
-
Usage notes
-
static_bm25() takes effect in the default basic sort expression named default.
-
Cases in which the static_bm25() score exceeds 1:
If query analysis, such as synonyms, is also configured for a query, the score can exceed 1. For example, the default query is query=index:'cellphone', and the query after synonyms are configured is query=index:'cellphone' OR index:'mobile phone'. If a document matches both cellphone and mobile phone, the static_bm25() scores are accumulated, and the final basic sorting score is greater than 1.
exact_match_boost: obtains the maximum weight among the user-specified query terms in a query
-
Usage: exact_match_boost()
-
Parameters: none
-
Return value: int. Value range: [0, 99].
-
Scenario: The query is query=default:’open search’^60 OR default:’opensearch’^50, and you want to sort documents by the boost weight of the terms that are actually matched. If Document A contains "open search" and Document B contains "opensearch", Document A is ranked before Document B. The basic sort expression is exact_match_boost().
-
Usage notes
-
The fields on which the function parameters depend must be created as indexes.
-
For query terms without a specified boost value, the default boost value is 99.
-
For exclusive applications, when the exact_match_boost function is configured in basic sorting, two parameter settings are supported: [‘sum’, ‘max’].
-
timeliness: timeliness score, used to measure how recent a document is
-
Usage: timeliness(pubtime)
-
Parameter pubtime: the field to be evaluated. The field must be of the int type, and the unit is seconds.
-
Return value: float. Value range: [0,1]. A larger value indicates better timeliness. If the value is later than the current time, 0 is returned.
-
Scenario: Specify the timeliness of the create_timestamp field in basic sorting. Set the expression to timeliness(create_timestamp).
-
Usage notes
-
The pubtime field must be configured as an attribute field.
-
timeliness_ms: timeliness score, used to measure how recent a document is
-
Usage: timeliness_ms(pubtime)
-
Parameter pubtime: the field to be evaluated. The field must be of the int type, and the unit is milliseconds.
-
Return value: float. Value range: [0,1]. A larger value indicates better timeliness. If the value is later than the current time, 0 is returned.
-
Scenario: Specify the timeliness of the create_timestamp field in basic sorting. Set the expression to timeliness_ms(create_timestamp).
-
Usage notes
-
The pubtime field must be configured as an attribute field.
-
normalize: normalization function that normalizes values to [0, 1] based on different scores
-
Scenario overview: During relevance calculation, the quality of a document needs to be measured from different dimensions. The score ranges of these dimensions may differ. For example, the number of clicks on a web page can be in the millions or tens of millions, whereas the text relevance score of a web page is within [0, 1]. These values are not comparable. To use these elements in a formula, you must normalize the different scores to the same value range, and normalize provides a simple way to do so. normalize supports three normalization methods: linear function conversion, logarithmic function conversion, and arctangent function conversion. normalize automatically selects a normalization method based on the parameters that are passed in. If only the value parameter is specified, normalize uses arctangent function conversion. If the value and max parameters are specified, normalize uses logarithmic function conversion. If value, max, and min are specified, normalize uses linear function conversion.
-
Usage: normalize(value, max, min)
-
Parameters: value: the value to be normalized. Floating-point numbers of the double type are supported. The value can come from a field in the document or from another expression. max: the maximum value of value. Optional. Floating-point numbers of the double type are supported. min: the minimum value of value. Optional. Floating-point numbers of the double type are supported.
-
Return value: double, a value within [0, 1].
-
Scenario 1: To normalize the price field when the value range of price is unknown, use the following formula: normalize(price)
Scenario 2: To normalize the price field when only the maximum value of price is known to be 100, use the following formula: normalize(price, 100)
Scenario 3: To normalize the price field when the maximum value of price is known to be 100 and the minimum value is known to be 1, use the following formula: normalize(price, 100, 1)
Scenario 4: To normalize the result of the distance function to [0, 1], use the following formula: normalize(distance(longitude_in_doc, latitude_in_doc, longtitude_in_query, latitude_in_query))
-
Usage notes:
-
Function parameters must be created as attributes.
-
When the arctangent function is used for normalization, if value is less than 0, the normalized value is 0.
-
When the logarithmic function is used for normalization, the value of max must be greater than 1.
-
When the linear function is used for normalization, max must be greater than min.
-
category_score: category prediction function
Description: Returns the category match score between the category field specified in the parameter and the category predicted for the query.
-
Usage
category_score(cate_id)
-
Parameters
cate_id: the field used as the category ID during training. The field must be of the int type.
-
Return value: INT. Value range: [0,2].
-
Scenario: For more information, see the scenarios in Use the category prediction feature. Set the expression to category_score(cate_id).
-
Usage notes
-
This function must be used together with the category prediction algorithm feature.
-