0

I am trying to implement a custom boosting rule (as described here) for the site search scope, where an item should be boosted by the time passed since last updated. For the record - we already implemented an index-time boosting rule for this which works, but a query-time boosting approach is more accurate since we don't plan a regular index rebuild.

So I use the resolveBoostingQuery (see here) pipeline to insert the custom rule:

where the update field is less than maximum days of [value,Integer,,number]

In code I use try to calculate the time passed with the update date field but I get the error:

Exception: System.NotSupportedException
Message: Invalid Method Call Argument Type: Field - FieldNode - Field: __smallupdateddate_tdt - System.DateTime. Only constant arguments is supported.

This is my code for now:

public override void ResolveBoostingQuery(ResolveBoostingQueryEventArgs args)
{
    var condition = args.RuleCondition as WhereRecentUpdate<RuleBoostingContext>;
    
    var expression = PredicateBuilder.True<ContentPage>();      
    var updatedExpression = PredicateBuilder.True<ContentPage>();
    updatedExpression = updatedExpression.And(page => DateTime.UtcNow.Subtract(page.Updated).TotalDays < condition.Value);
    
    args.Predicate = expression.And(updatedExpression).Boost(CalculateTimePassedBoost(args.Boost, condition.Value));
}

private float CalculateTimePassedBoost(float boost, int daysPassed) { ... }

It's not easy to find complex examples of how to use Sitecore Content Search predicates and I didn't find a good way to debug yet. Do you have an example to follow or an idea how to implement this feature?

Thanks

1 Answer 1

1

You are facing above issue due to Datetime comparison. Inside Solr, you can use between operator to perform datetime comparison with the below code:

var updatedExpression = PredicateBuilder.True<SearchResultItem>();
updatedExpression = updatedExpression.And(page => page.Updated.Between(DateTime.UtcNow.AddDays(-5), DateTime.UtcNow, Inclusion.Both));                   

This will solve the above issue you are encountering. You can find more details on the supported operator's in Solr here:

https://doc.sitecore.com/xp/en/developers/82/sitecore-experience-platform/linq-to-sitecore.html

Hope this helps!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.