Gravatar for shirazi@rdacorp.com

Question by aga, Oct 28, 2015 11:32 AM

Field based boosting

Hi,

I'm using coveo for Sitecore and I'm looking for a way to boost data on a specific field (not template, but a field on the item). My data has title and description fields and I always want to boost the results when the title is matched. I can't use the field or item based boosting rule as they are looking for specific values on the item, but I want to query driven. For example, when a user enters Motorola, i want any matches on the title boosted.

UPDATE 1 So looks like what I'm asking for is weights and not really boosting. But how can I weight specific fields?

1 Reply
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Oct 29, 2015 1:20 AM

The title of search results is already weighted with the ranking weights you mentioned. Unfortunately, you cannot weight individual fields.

What you ask for is a boosting rule "Where a specific field compares to the searched terms". This rule doesn't exist by default. You would have to code it in JavaScript.

You can add an event handler to the "doneBuildingQuery" event (see Events) and add the query ranking expression like this:

.on("doneBuildingQuery", function(e, args) {
    args.queryBuilder.advancedExpression.add("$qre(expression:'<%= ToCoveoFieldName("YourFieldName") %> == \"' + args.queryBuilder.expression.build() + '\"', modifier:'100')");
})

The problem here is that the query can contain more than just words and you can end up with an invalid expression for your QRE. If the query is "exact phrase" or @field=value, you would have problems with your QRE.

Ask a question