Debugging Tips and Best Practices of Coveo Custom Computed Fields in Sitecore
Debugging Tips
Log Browser
Navigate to the Coveo cloud platform and select Log Browser in the content section, which is essential for troubleshooting indexing issues. Each log in the Log Browser represents an item at a stage of the indexing pipeline.
Coveo Logs
Coveo for Sitecore uses log4net and generates logs in the defined location defaults to app_data/logs. Lower the logging level in development to increase logging.
https://docs.coveo.com/en/2147/coveo-for-sitecore-v5/analyze-the-rebuild-process
Reindex
Enable the developer toolbar by right-clicking on the ribbon in the content editor. Select the item and choose the ReIndex tree. Ensure you choose a single item and not the home node. While doing this, attach the debugger in Visual Studi,o and you will see it going through the Computed fields.
Content Browser
Navigate to the Coveo cloud platform and select Content Browser in the content section; it will help you search for an item and look for the fields.
Hold the Alt key when you click on an item, and it will display the item with all the fields available in the index.
Best Practices
I am sharing some of the tips and common best practices when you use the Coveo Custom Computed fields in Sitecore. Let's start with the definition of the computed field.
FieldName
The field name can be defined in the C# implementation or the configuration. I recommend using the configuration that gives more flexibility and avoids a need for code change.
ReturnType
The Default Return type is string but you could use other types listed. This can be achieved only in the code and cannot be done in configuration. Sitecore data type to Coveo mapping as follows.
Sitecore | Coveo |
---|---|
String | String |
Integer | Integer |
Number | Floating Point |
Date | Date/Time |
DateTime | Date/Time |
Ensure the date/time format matches (yyyy/MM/dd@HH:mm:ssZ)
ComputedFieldValue Method
A few key considerations while you do the computedfieldvalue method.
- When the function call enters the method, check for the required template, and if it doesn't match, return right away. Helps keep the indexing efficient and reduces indexing time.
- Always return null if there is no value, and do not return an empty string. The reason behind this is that if the value is null, it will skip adding the value to the index.
- Do not try to use Sitecore Search to make any computations.
- Ensure the method is efficient, with no long-running tasks or calls to an external web service to compute the values.
FieldNames
- No special characters in the field name definition
- Match the field name to the computed field class name
Config
- Manage the field definition in the config files
- Reindex or Sync to get the field definition pushed to the cloud
- If you make changes directly on Coveo Cloud it will reset on sync
https://docs.coveo.com/en/2251/coveo-for-sitecore-v5/computed-fields
Subscribe to Bala Blog | Sitecore MVP | Coveo MVP | DX MVP | Sitecore | Coveo | Microsoft
Get the latest posts delivered right to your inbox