All Products
Search
Document Center

:multi_attr

Last Updated:Mar 03, 2023

Functionality functions

You can use functionality functions in filter clauses to define filter conditions. Functionality functions that return numeric values can be used in sort clauses for sorting.

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

multi_attr: Returns the value of the specified array field at the specified position

1. Syntax

multi_attr(field, pos, default_value=0|"")

2. Parameters

  • field: the name of the field whose value is to be obtained. This parameter must be of the ARRAY type. The specified field must be configured as an attribute field.

  • pos: the subscript that indicates a position, which starts from 0. This parameter specifies an integer constant or integer field. The specified field must be configured as an attribute field.

  • default_value: optional. This parameter specifies a string constant. If the value at the position specified by the pos parameter does not exist, the value of the default_value parameter is returned.

3. Return value

  • If the value at the position specified by the pos parameter exists, this value is returned.

  • If the value at the position specified by the pos parameter does not exist and the default_value parameter is not specified, 0 is returned.

  • If the value at the position specified by the pos parameter does not exist and the default_value parameter is specified, the value of the default_value parameter is returned.

4. Scenarios

Scenario 1: Commodities have multiple prices, including market prices, discount prices, and sales prices. The prices are recorded in the price field. You can use the following query clause to search for mobile phones whose sales price is less than 1,000:

query=default:'Mobile phone'&&filter=multi_attr(price,2)<1000

Scenario 2: Commodities have multiple prices, including market prices, discount prices, and sales prices. The prices are recorded in the price field. You can use the following query clause to sort query results in ascending order of discount prices. If no discount price exists or if the price field is empty, the value 600 is assigned to the price field by default.

query=default:'Mobile phone'&&sort=+multi_attr(price,1,"600")

5. Usage notes

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

  • The value of the default_value parameter must be enclosed in double quotation marks ("").