All Products
Search
Document Center

:gauss_decay

Last Updated:Mar 31, 2026

Feature functions

Feature functions can be used in sort expressions. Most of these functions support only fine sort expressions. You can combine various syntax and statements to implement powerful sorting features.

Document fields used as feature function parameters must be created as indexes or properties as specified in the function's documentation.

gauss_decay: Uses a Gaussian function to calculate attenuation based on the distance between a value and a given origin point

1. Usage details:

gauss_decay(origin, value, scale, decay, offset)

2. Parameters:

  • origin: The origin point of the attenuation function. The value must be a double.

  • value: The value used to calculate the attenuation. The value must be a double and can be obtained from a document field or another expression.

  • scale: The rate of attenuation. The value must be a double.

  • decay: The degree of attenuation when the distance from the origin equals the scale. The value must be a double. This parameter is optional. The default value is 0.000001.

  • offset: Attenuation is calculated only when the distance from the origin is greater than the offset. The value must be a double. This parameter is optional. The default value is 0.

3. Return value:

Returns a double value in the range of [0, 1].

4. Scenarios:

Scenario 1:

Find hotels closest to a user, sorted by distance from nearest to farthest. Hotels within 100 m are considered equally close. In this scenario, `longitude_in_doc` and `latitude_in_doc` are the longitude and latitude of the hotel, and `longitude_in_query` and `latitude_in_query` are the longitude and latitude of the user.

gauss_decay(0, distance(longitude_in_doc, latitude_in_doc, longtitude_in_query, latitude_in_query), 5, 0.000001, 0.1)

Scenario 2:

Find mobile phones with a price around USD 300. The document score is 0 if the price is less than 200 or greater than 400. The phone price in the document is `price`, and `kvpairs=price_key:2000`. The formula is as follows:

 gauss_decay(kvpairs_value(price_key, FLOAT), price, 500)

5. Notes:

  • The function parameters must be created as properties.

  • If `scale` is less than or equal to 0, the function returns 0.

  • If `decay` is greater than or equal to 1, the function returns 1.

  • If `decay` is less than or equal to 0, its value is set to 0.000001.

  • If `offset` is less than 0, its value is set to 0.