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