Gravatar for jfallaire@coveo.com

Question by Jean-Francois Allaire, May 6, 2014 9:01 AM

How to use Ranking Function using the Javascript Search UI

My Ranking Function doesn't seems to be applied correctly, am I missing something (see code below)?

$('#search').on('doneBuildingQuery', function (e, data) {
   data.queryBuilder.rankingFunctions = [{"expression":"@syssource==\"MySource\"", "normalizeWeight":true}];
   console.log(["final queryBuilder >>>"].concat(data));
});

$('#search').coveo('init');

As you can see below the rankingFunctions is added to the queryBuilder:

alt text

However, when i look at the "performing REST query" trace in browser console, I don't see anything related to ranking

alt text

Gravatar for mlaporte@coveo.com

Comment by Martin Laporte, May 6, 2014 9:16 AM

Ranking function support is pretty recent. What version are you using?

Gravatar for glaporte@coveo.com

Comment by Gregory Laporte, May 6, 2014 9:18 AM

When you GET /rest/search/extensions, do you see $qrf and $qf in the list of available query extensions?

Gravatar for jfallaire@coveo.com

Comment by Jean-Francois Allaire, May 6, 2014 10:03 AM

if i want to add qre, should i use query extension or rankingFunctions?

Gravatar for apare@coveo.com

Comment by Alexandre Paré, May 6, 2014 11:23 AM

You should use extension. Here you have two examples how to do add QRE. https://developers.coveo.com/display/JsSearch/Using+Query+Ranking+Expressions QRE: the expression result is an boolean, if true add the boost. RankingFunctions: the expression result is an number, add a boost depending on the value.

1 Reply
Gravatar for apare@coveo.com

Answer by Alexandre Paré, May 6, 2014 9:25 AM

This is enabled only on the may build (JS Search: 0.9.445)

EDIT

In this particular case you should use qre. This code should work :

var createQre = function (expression, modifier) {
    return "$qre(expression:'" + expression + "', modifier:'" + modifier + "')";
};

$('#search').on('doneBuildingQuery', function (e, data) {
   var qre = createQre("@syssource==\"MySource\"", 200)
   data.queryBuilder.advancedExpression.add(qre);
});

$('#search').coveo('init');

You can change the weight of the modifier to make the car more or less relevant

Gravatar for jfallaire@coveo.com

Comment by Jean-Francois Allaire, May 6, 2014 10:01 AM

make sense! thanks

Ask a question