This topic describes the members of the structure defining a single Query Function to perform during a request. A Query Function is a mathematical expression that you run during a request to calculate a value for each result at query time, and output its result in a dynamic field.
The Query Function syntax is:
You can also chain multiple query functions and use the result of one in another.
The following list contains all parameters available when executing a query function using the REST Search API.
function: The function to execute
The mathematical expression that calculates the value to inject in the field.
The Coveo query function supports the syntax of the C++ Mathematical Expression Library ExprTk (see ExprTk Library).
Be aware that the following statements have been disabled:
dist function was added to the supported query functions, on top of the ExprTK library functions. The
dist function syntax is:
The returned value is in meters.
fieldName: Name of the field that will hold the results
This specifies the name of the field to be generated at query time. This field can be used as a facet or as a computed field.
To prevent performance issues, every computed field referenced in the function must be stored in memory. Not doing so may lead to serious performance issues, with queries that might take over a second, depending on your number of items.
This is because query functions are executed on all accessible items. If the computed field is not stored in memory, it might have to be loaded from the disk, which can significantly slow the query.
Solve the Issue in Cloud V2
When using Cloud V2, for instance in a Coveo for Sitecore Cloud edition environment, follow these steps:
- Access the Coveo Cloud Platform.
- Under Content, select Fields.
- Search for the field you wish to store in cache.
- Select your desired field, and click Edit.
- In the Edit a Field window, select Advanced Settings.
Select Use cache for numeric queries.
- Select Save Field to save your changes.
Solve the Issue in Cloud V1
In a Cloud V1 environment, for instance when using Coveo for Salesforce, you cannot manually change this setting. For security reasons, the ability to change the configuration file has been limited to selected Coveo employees. To change this setting, contact Coveo Support.
Solve the issue in CES
In an on-premises environment using Coveo Enterprise Search, this setting is changeable in a configuration file, where your fields can be added to the
A few query exceptions can be returned when using Query Functions:
, Using the
character without any field name.
, Using a field that doesn't exist in the index, nor in any prior query function.
, Using a field that is not a numerical field.
, Syntax error in the expression.