Gravatar for tony.gonzalez@razorfish.com

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

Displaying Results Only When a Query Is Made Not working

Hi,

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() {
            Coveo.$('#search')
                // 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: https://developers.coveo.com/display/public/JsSearchV1/Displaying+Results+Only+When+a+Query+Is+Made

Please advise.

Thanks.

-t

1 Reply
Gravatar for sbelzile@coveo.com

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 tony.gonzalez@razorfish.com

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