All Products
Search
Document Center

OpenSearch:Fine sort functions

Last Updated:Mar 06, 2023

Fine sort expressions are used to score and sort the roughly sorted results and return the optimal results. 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 provides expression templates for you to perform searches on 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

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

  1. text_relevance: calculates the text relevance between search queries and field values in documents.

  2. 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.

  3. 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.

  4. fieldterm_proximity: returns the proximity of terms in a field.

  5. field_length: returns the number of terms in a field.

  6. query_term_count: returns the number of terms in the search query after analysis.

  7. query_term_match_count: returns the number of terms in the search query that are hit in a specific field in documents.

  8. field_term_match_count: returns the number of terms that match the search query in a field.

  9. 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

  1. distance: returns the spherical distance between two points. Generally, this function is used in distance calculation for a location-based service (LBS).

  2. gauss_decay: uses a Gaussian function to calculate the decay degree based on the distance between values and a specified start point.

  3. linear_decay: uses a linear function to calculate the decay degree based on the distance between values and a specified start point.

  4. exp_decay: uses an exponential function to calculate the decay degree based on the distance between values and a specified start point.

Timeliness

  1. timeliness: returns the timeliness score that indicates how new a document is. Unit: seconds.

  2. timeliness_ms: returns the timeliness score that indicates how new a document is. Unit: milliseconds.

Algorithm relevance

  1. category_score: the category prediction function that returns the matching score between the specified category field in the parameters and the category obtained by the category prediction query.

  2. popularity: returns the popularity score of a commodity. The score indicates the popularity of the commodity.

Functionality

  1. tag_match: matches query clauses with documents based on tags and scores the documents by calculating the weights of matched tags.

  2. first_phase_score: returns the score that is calculated by using rough sort expressions.

  3. kvpairs_value: returns the value of the specified field in a kvpairs clause in a query.

  4. normalize: normalizes scores in different value ranges to numeric values in the range of [0,1].

  5. in or notin: checks whether field values are in a specific list.