Dictionary Field in Coveo
Coveo organization source automatically comes with a set of standard system fields. By using the dictionary field, data can be stored in a key-value pair. The most common use case is in the catalog source where we want to store customer prices based on the user's account or location.
Dictionary fields are only supported by the Push API and the Stream API. String or numeric values can be stored by using the dictionary field and then pass the context key when an end user performs a query.
For this blog, we will use the following example: I want to store the customer price data of a product based on the logged-in user account ID.
- Create the "customerprice" field in the Coveo organization and set the field type as string. Pass values in the key-value pair so it will automatically convert in the Dictionary field. Using the Push API, store below JSON data for the catalog source.
- Coveo will index all different values under the "customerprice" field.
- By using the empty string "" as a key we can specify the default value.
-
If context is not provided then the default value will be rendered for "customerprice". For Product 1 the default value is 2200 and for Product 2 the default value is 1200.
-
Specify the Dictionary key by using the DictionaryFieldContext to retrieve its value. Please refer the below Image In line number 15. We have specified the dictionary fieldname "customerprice" and key "customer101" in the dictionary field context. So when a user tries to log in to the website at that time the store user's account ID will act as a dictionary field key.
- Specify field name in the atomic-result-number to retrieve field value of "customerprice"