Fine sort expressions are used to score and sort the roughly sorted results to return the optimal results to you. You can customize sort expressions for applications and specify sort expressions in search queries to sort results. Sort expressions support basic operations, mathematical functions, and feature functions. The basic operations include arithmetic, relational, logical, bitwise, and conditional operations. OpenSearch allows you to sort search results by relevance in typical applications, such as forum and news applications. You can select an appropriate expression template based on your data characteristics and modify the selected template to generate a custom expression. This topic describes supported fine sort functions.
Note: To perform basic operations such as arithmetic, relational, logical, and conditional operations, you must use numbers or field values of the NUMERIC type in sort expressions. Most function-based operations cannot be performed on values of the STRING type.
Text relevance
text_relevance: calculates the text relevance between search queries and field values in documents.
field_match_ratio: returns the ratio of the number of terms that match the search query to the total number of terms in a field.
query_match_ratio: returns the ratio of the number of terms that are hit in a specific field to the total number of terms in the search query.
fieldterm_proximity: returns the proximity of terms in a field.
field_length: returns the number of terms in a field.
query_term_count: returns the number of terms in the search query after analysis.
query_term_match_count: returns the number of terms in the search query that are hit in a specific field in documents.
field_term_match_count: returns the number of terms that match the search query in a field.
query_min_slide_window: returns the ratio of the number of terms in the search query that are hit in a specific field to the minimum window of these terms in the field.
Geographical location relevance
distance: returns the spherical distance between two points. Generally, this function is used in distance calculation for a location-based service (LBS).
gauss_decay: uses a Gaussian function to calculate the decay degree based on the distance between values and a specified start point.
linear_decay: uses a linear function to calculate the decay degree based on the distance between values and a specified start point.
exp_decay: uses an exponential function to calculate the decay degree based on the distance between values and a specified start point.
Timeliness
timeliness: returns the timeliness score that indicates how new a document is in the unit of seconds.
timeliness_ms: returns the timeliness score that indicates how new a document is in the unit of milliseconds.
Functionality
tag_match: matches query clauses with documents based on tags and scores the documents by calculating the weights of matched tags.
first_phase_score: returns the score that is calculated by using rough sort expressions.
kvpairs_value: returns the value of the specified field in a kvpairs clause in a query.
normalize: normalizes scores in different value ranges to numeric values in the range of [0,1].
in or notin: checks whether field values are in a specific list.