All Products
Search
Document Center

:fieldterm_proximity

Last Updated:Mar 03, 2023

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.

fieldterm_proximity: returns the proximity of terms in a field

    1. Syntax

    fieldterm_proximity(field_name,index_name)

    2. Parameters

    • field_name: optional. The name of the field for which you want to obtain the proximity of terms. The field must be of the TEXT or SHORT_TEXT type. An analyzer must be enabled for the field. The analyzer can be the general analyzer for Chinese, a custom analyzer, the single character analyzer for Chinese, the analyzer for English, or the analyzer for fuzzy searches.

    • index_name: optional. The name of the index that is created on the field specified by the field_name parameter.

    3. Return value

    The return value is of the FLOAT type. Valid values: 0 to 1.

    4. Scenarios

    Scenario 1:

    In the fine sorting stage, the proximity of the title and body fields in the query is calculated. The proximity of the title field is weighted higher in sorting. You can use the following fine sort expression:

    fieldterm_proximity(title)*10 + fieldterm_proximity(body)

5. Usage notes

  • The fields that you reference in the parameters of this function must be configured as index fields.

  • Measurement metrics: the distance between and order of hit words in the field.

  • This feature is used only for fine sorting and is included in text_relevance(). In regular scenarios, you do not need to use the fieldterm_proximity() and text_relevance() functions together.