Coveo for Sitecore: Ranking Expressions within the Coveo Query Pipelines

Out of the box, Coveo for Sitecore uses the Sitecore system date fields to check freshness of content. For some this may work as any update will modify those dates. However, in some cases you may want to use a custom date field.



My scenario: no matter when the last update was made, the content should be boosted based on the base template field, ContentDate. I wrote a computed field called ComputedContentDate with some logic to cover scenarios such as Events where the start date of the event should be used over the ContentDate field.

Within the Query Pipeline, first go in and modify the ranking weights. I lowered Item Last Modification to zero. This removes the out of the box boosting based on the Sitecore system date fields.  Next go into Ranking Expressions and add rules for your new date field.

Boost by +50: Today
@fcomputedcontentdate13080=today
@fcomputedcontentdate2110=today

Boost by +40: Yesterday
@fcomputedcontentdate13080=yesterday
@fcomputedcontentdate2110=yesterday

Boost by +30: Within 7 days but not yesterday OR today
@fcomputedcontentdate13080>=today-7d AND @fcomputedcontentdate13080<yesterday
@fcomputedcontentdate2110>=today-7d AND @fcomputedcontentdate2110<yesterday

Boost by +20: Within 1 month but not within 7 days
@fcomputedcontentdate13080>=today-1mo AND @fcomputedcontentdate13080<today-7d
@fcomputedcontentdate2110>=today-1mo AND @fcomputedcontentdate2110<today-7d

Boost by +15: Within 3 months but not within 1 month
@fcomputedcontentdate13080>=today-3mo AND @fcomputedcontentdate13080<today-1mo
@fcomputedcontentdate2110>=today-3mo AND @fcomputedcontentdate2110<today-1mo

Boost by +10: Within 1 year but not within 3 months
@fcomputedcontentdate13080>=today-1yr AND @fcomputedcontentdate13080<today-3mo
@fcomputedcontentdate2110>=today-1yr AND @fcomputedcontentdate2110<today-3mo

Note: The reason for duplication is that the CM and CD environments use different fields due to the way Coveo hashes the field names.

The above solution will now boost fresher content based on a date of your choosing! I'm still fairly early on in my Coveo for Sitecore implementation so the boost values may change over time but this is what I'm initially rolling out.

Comments