Gravatar for

Question by Tony, Feb 25, 2016 12:39 PM

Displaying Results Only When a Query Is Made Not working


I'm having an issue trying to block the initial search from getting triggered without entering a keyword.

I am initializing my componentsOption such as:

Coveo.$(function() {
            CoveoForSitecore.componentsOptions = @(Html.Raw(Model.GetJavaScriptInitializationOptions()));
            CoveoForSitecore.componentsOptions.SearchInterface = {};
            CoveoForSitecore.componentsOptions.SearchInterface.autoTriggerQuery = false;
            CoveoForSitecore.componentsOptions.SearchInterface.hideUntilFirstQuery = true;
            CoveoForSitecore.componentsOptions.SearchInterface.enableHistory = false;


and then I'm passing that object to the 'init' method such as:

 Coveo.$(function() {
                // Add a filter expression to display only items that have "Show In Search Results" checked
                .on("buildingQuery", function(e, args) {
                    args.queryBuilder.advancedExpression.add('(@Model.ToCoveoFieldName("Show In Search Results") == "1")');
                .coveoForSitecore('init', CoveoForSitecore.componentsOptions);

However, When I load the page I'm still seeing general results.

I followed the instructions on this page:

Please advise.



1 Reply
Gravatar for

Answer by Sébastien Belzile, Feb 25, 2016 1:28 PM

  1. With Coveo for Sitecore 3.0, you should not use JS Search V1 documentation. C4SC 3.0 uses JS Search V0.9. Coveo for Sitecore 4.0 will use JS Search V1.
  2. The options you are trying to add manually are fronted on the Coveo Search Component. You could use these options instead. I tested it, it works properly.
  3. The reason why your code does not work is because the data-[options] declared on your CoveoSearch component have priority over options declared for the class SearchInterface in the 'init' call.
Gravatar for

Comment by Tony, Feb 25, 2016 1:51 PM

I wanted to always default to these options regardless if the author selected the options (or not) in the component.

The issue was with the priority order.

Thank for the help sbelzile.

Ask a question