All Products
Search
Document Center

:gauss_decay

Last Updated:Sep 09, 2021

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 clauses to perform complex sorts.

The fields that you reference in parameters of feature functions must be configured as index or attribute fields based on the description of each function.

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

1.Syntax:

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

2.Parameters:

  • origin: the start point. The value of this parameter must be a double-precision floating-point number.

  • value: the user-defined field or the expression for which you want to calculate the decay degree. The value of this parameter must be a double-precision floating-point number.

  • scale: the scale that is used to calculate the decay degree. The value of this parameter must be a double-precision floating-point number.

  • decay: the decay degree when the distance equals to the value of the scale parameter. This parameter is optional. The value of this parameter must be a double-precision floating-point number. Default value: 0.000001.

  • offset: the decay degree starts to be calculated when the distance is greater than the offset. This parameter is optional. The value of this parameter must be a double-precision floating-point number. Default value: 0.

3.Return values:

The return value is of the DOUBLE type. Valid values: [0,1] .

4.Scenarios:

Scenario 1:

You want to search for the nearest hotel. The nearby hotels are sorted from near to far, and the hotels that are less than 100 meters away from you are not sorted. longitude_in_doc and latitude_in_doc specify the longitude and latitude of a hotel. longitude_in_query and latitude_in_query specify the longitude and latitude of your location.

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

Scenario 2:

You want to search for a mobile phone that costs about CNY 2,000. If the price of a mobile phone is less than CNY 1,500 or greater than CNY 2,500, the document that contains the mobile phone scores zero. The price of a mobile phone is indicated by the price field in a document. The start price is defined in the kvpairs=price_key:2000 format. The following expression is used:

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

5.Usage notes:

  • The field that you reference in the parameter of this function must be configured as an attribute field.

  • If the value of the scale parameter is less than or equal to 0, the gauss_decay function returns 0 by default.

  • If the value of the decay parameter is greater than or equal to 1, the gauss_decay function returns 1 by default.

  • If the value of the decay parameter is less than or equal to 0, the decay parameter is set to 0.000001 by default.

  • If the value of the offset parameter is less than 0, the offset parameter is set to 0 by default.