Feature functions
You can use feature functions in sort expressions. Most feature functions can be used only in fine sort expressions. You can combine various syntax and statements to conduct complex sorts.
The fields that you reference in feature functions must be configured as index fields or attribute fields based on the description of each function.
text_relevance: calculates the text relevance between search queries and field values in documents
1. Syntax
text_relevance(field_name,index_name,params )
2. Parameters
field_name: required. The name of the field. An analyzer must be enabled for the field. The analyzer can be a common analyzer for Chinese, custom analyzer, or single character analyzer for Chinese. The field must be configured as an index field.
index_name: optional. The name of the index that is created on the field specified by the field_name parameter.
params: optional. The score calculation logic. A value of true indicates that the maximum score among documents in the index group obtained by query analysis is used. A value of false indicates that the sum of scores of all documents in the index group obtained by query analysis is calculated. Default value: false. For example, the synonym configuration result for query=index:'Kentucky Fried Chicken' is query=index:'Kentucky Fried Chicken' OR index:'kfc'.
3. Return value
The return value is of the FLOAT type. Value range: 0 to 1.
4. Scenarios
Scenario 1: Calculate the text relevance for the title and body fields by using a fine sort expression. If the weight ratio of the title field to the body field is 3:1, the fine sort expression is text_relevance(title)*3+text_relevance(body)
.
Scenario 2: Calculate the text relevance for the title_index index that is created on the title field by using a fine sort expression. The sum of scores of all documents in the index group generated by query analysis is used. The fine sort expression is text_relevance(title,title_index,false)
.
5. Usage notes
The field that you reference in the parameter of this function must be configured as an index field.
Measurement metrics: the proportion of hit words in the search query, the proportion of hit words in the field, the frequency of hit words in the field, the order of hit words in the field, and the order of hit words in the search query.
This function can be used only in fine sort expressions.