ReQL Functions
Functions may be used to enhance your ReQL queries – for example up-sell or getting nearby items can be achieved easily by functions.
There are various functions like math functions (rounding, computing square root …), string functions (converting case), function for getting size of set or string, getting current timestamp, functions for conversions between types (for example conversion between date in a text representation and timestamp) or even lambda functions. If you are missing some function that you would like to use, please let us know.
ReQL function can take arguments and returns a single value. Arguments are placed between parentheses and are separated by commas – for example computing base 2 logarithm of 8 looks like this: log(8,2). If the function takes no arguments the parentheses may be omitted (for e.g. now). If the function is given wrong number of arguments, or the arguments have unsupported type, an error is produced. If any of the arguments is null, then result is also a null value.
Quick Overview
Context
| Name | Description | Example |
|---|---|---|
| context_item | Retrieves property value of the item, that is currently viewed by the user. | |
| context_user | Retrieves property value of the user, that is about to obtain the recommendations. | |
| context_segment | Retrieves the Segment on which the recommendations are based |
Miscellaneous
| Name | Description | Example |
|---|---|---|
| now | Returns current timestamp | |
| random | Returns a random number between 0 and 1 | |
| size | Returns the length of a string or number of objects in a set | |
| item_values | Returns property values of a particular item as a dictionary | |
| reduce | Reduces a set into a single value using an operator |
Lambda
| Name | Description | Example |
|---|---|---|
| map | Applies the lambda expression to every member of a set | |
| select | Returns only those values of input set for which the lambda expression returns true | |
| exists | Returns true if lambda expression is satisfied for at least one element of the input set |
Type Conversion
| Name | Description | Example |
|---|---|---|
| boolean | Converts the argument to boolean | |
| number | Converts the argument to number | |
| string | Converts the argument to string | |
| timestamp | Converts the argument to timestamp |
Math
| Name | Description | Example |
|---|---|---|
| max | Returns the maximum of n arguments | |
| min | Returns the minimum of n arguments | |
| avg | Returns the average of n numbers | |
| round | Returns closest integer | |
| floor | Returns largest preceding integer | |
| ceil | Returns smallest following integer | |
| abs | Returns non-negative value of the argument without regard to its sign | |
| sqrt | Returns the square root of the argument | |
| pow | Returns 𝑓𝑖𝑟𝑠𝑡_𝑎𝑟𝑔𝑢𝑚𝑒𝑛𝑡𝑠𝑒𝑐𝑜𝑛𝑑_𝑎𝑟𝑔𝑢𝑚𝑒𝑛𝑡 | |
| log | Returns the logarithm of the argument |
String
| Name | Description | Example |
|---|---|---|
| upper | Converts all letters to the capital letters | |
| lower | Converts all letters to the small letters | |
| split | Splits a string into sub-strings using a separator |
Interactions Listing
| Name | Description | Example |
|---|---|---|
| user_interactions | Returns list of interactions by a particular user |
Interactions Statistics
| Name | Description | Example |
|---|---|---|
| num_item_bookmarks | Returns the number of bookmarks of an item | |
| num_item_detail_views | Returns the number of detail views of an item | |
| num_item_purchases | Returns the number of purchases of an item | |
| num_item_ratings | Returns the number of ratings of an item |
Item Segments Handling
| Name | Description | Example |
|---|---|---|
| segment_items | Get items in a Segment | |
| item_segments | Get Item Segments to which the item belongs |
Geographical
| Name | Description | Example |
|---|---|---|
| earth_distance | Returns the orthodromic distance between two points (given as their latitude and longitude in degrees) in meters | |
| geo_polygon | Creates a spherical polygon represented by points with geographical coordinates | |
| geo_radius | Creates a spherical cap represented by a center with geographical coordinates and a radius in km |