Gravatar for rvijay@cadence.com

Question by rvijay@cadence.com, May 24, 2018 11:25 PM

How to pass query expression to recommendations component

I'm using below code to initialize the recommendations and I need help to pass query expression for the results to be in sync with document opened

document.addEventListener("DOMContentLoaded", function() {
  Coveo.SearchEndpoint.configureCloudV2Endpoint(organizationId, accessToken);
  var searchInterfaceElement = document.querySelector('#search');
  Coveo.initRecommendation(document.querySelector("#recommendation"), searchInterfaceElement);
});
1 Reply
Gravatar for flguillemette@coveo.com

Answer by François Lachance-Guillemette, May 25, 2018 12:37 PM

The Recommendation component acts just like a Search Interface, so you can put `data-expression="YOUR_FILTER"` just like you would on a standard Search Interface.

You can also add a hook on the `buildingQuery` event (see Query Events) and add the expressions that you need (see Handling Query Events)

Gravatar for rvijay@cadence.com

Comment by rvijay@cadence.com, May 30, 2018 10:08 PM

I really don't need any search interface on the page where Recommendations component is added. Can you tell me how to resolve the error: "Recommendation component has no parent interface. Disabling responsive mode for this component."

<CoveoV2:JsSearch debug="true" filter="{!UserFilter}" additionalUserIdentities="{!AdditionalUserIdentities}" stylesheet="CoveoFullSearch.css">
    </CoveoV2:JsSearch>
    <script>   
        document.addEventListener('DOMContentLoaded', function () {
            Coveo.initRecommendation(document.querySelector("#recommendation"),document.querySelector("#search"));
        });
    </script>
    <div id="recommendation" data-results-per-page="5" data-pipeline="RecommendationsPipeline" data-hide-if-no-results="true" data-main-search-interface="search">
        <div data-search-hub='Demo'></div>
        <div>
            <div>Recommendations</div>
        </div>
        <div>
            <div></div>
        </div>
    </div>

Ask a question