Gravatar for bberriz@lifeextension.com

Question by Ben, Mar 18, 2015 10:07 AM

QREs not effecting results in Coveo for Sitecore

QREs I add to the queryBuilder are not modifying the results. Basic expressions and field expressions (even when using the same fields and values as those in the QRE) are working. I've tried the code below in both the buildingQuery and doneBuildingQuery event. I am able to see the QREs in the aq parameter of the query.

    var generateRankingExpression = function(expression, modifier) {
        if (!expression || !modifier) return "";

        return "$qre(expression:'" + expression + "', modifier:'" + modifier + "')";;
    };

    function addRankingExpressions(e, args) {
        // These work to modify the results
        @*args.queryBuilder.numberOfResults = 2;
        args.queryBuilder.expression.add('Restore');
        args.queryBuilder.expression.add("@@@Model.ToCoveoFieldName("Item Number", false)=01727");
        args.queryBuilder.expression.add("@@@Model.ToCoveoFieldName("hierarchicalcategory", false)=Products");*@

        // ...but none of these do.
        var qre = generateRankingExpression("@@@Model.ToCoveoFieldName("Item Number", false)=01727", "100");

        args.queryBuilder.advancedExpression.add(qre);

        qre = generateRankingExpression("@@@Model.ToCoveoFieldName("hierarchicalcategory", false)=Products", "100");

        args.queryBuilder.advancedExpression.add(qre);

        qre = generateRankingExpression("@@@Model.ToCoveoFieldName("hierarchicalcategory", false)=Magazines", "-100");

        args.queryBuilder.advancedExpression.add(qre);
    };

    Coveo.$('#search').on('buildingQuery', addRankingExpressions);
1 Reply
Gravatar for mlaporte@coveo.com

Answer by Martin Laporte, Mar 18, 2015 10:11 AM

First, several things to check:

  • Try with higher modifier (like 10000) just to be sure.
  • Make sure the expressions passed in the QREs match any document when combined with the other filters?
  • Be sure that the search page is sorting with Relevancy (the default).

Then, how many results does your query returns?

Gravatar for bberriz@lifeextension.com

Comment by Ben, Mar 18, 2015 10:30 AM

Thanks for the quick response!
I had already gone through your first two suggestions, and the sortCriteria of queryBuilder was set to relevancy, so I assumed everything was fine, but I completely overlooked the fact that the sorting was being overridden. Problem solved, thanks again!

Ask a question