Feature functions
You can use feature functions in sort expressions. Most feature functions are supported only in fine sort expressions. You can combine various syntax and statements to create powerful sorting features.
You must configure document fields that are used as function parameters as an index or a property, as specified in the documentation for the corresponding function.
text_relevance: Calculates the text-matching relevance of keywords in a field.
1. Usage details:
text_relevance(field_name, index_name, params)
2. Parameters:
field_name: The name of the field. This parameter is required. The field must use a tokenization method such as Chinese basic, custom, or single-word tokenization. It must also be configured as an index field.
index_name: The name of the index that corresponds to `field_name`. This parameter is optional.
params: The scoring logic. This parameter is optional. The default value is `sum`. `true` specifies that the system uses the `max` score from the documents in the index group that is expanded by query analysis. `false` specifies that the system uses the `sum` of the scores. For example, a query `index:'KFC'` is expanded using a synonym to `index:'KFC' OR index:'kfc'`.
3. Return value:
float. The value is in the range [0, 1].
4. Scenarios:
Scenario 1: In a fine sort expression, calculate text relevance scores for the `title` and `body` fields with a weight ratio of 3:1. text_relevance(title)*3+text_relevance(body)
Scenario 2: In a fine sort expression, calculate the text relevance score for the `title_index` index, which corresponds to the `title` field, and use the `sum` function to aggregate scores for the index group expanded by query analysis. text_relevance(title,title_index,false)
5. Notes:
You must create an index for any field that is used as a parameter in this function.
The score is primarily based on the following factors: the proportion of hit terms in the query, the proportion of hit terms in the field, the frequency of hit terms in the field, and the similarity between the order of hit terms in the field and their order in the query.
This function can be used only in fine sort expressions.