Gravatar for arulselvan.arivazhagan@cfainstitute.org

Question by Arulselvan, Mar 21, 2018 2:09 PM

Set default queries and properties while adding search view

When i add search view in the page as component. I need few queries and properties has to be set by default. Is it possible?

kindly advise on this.

thanks in advance.

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Mar 21, 2018 2:41 PM

Is it for the new Coveo for Sitecore Hive framework (v4.1 and up only) or the Legacy UI framework (v3.0 to v4.1)?

Gravatar for arulselvan.arivazhagan@cfainstitute.org

Comment by Arulselvan, Mar 21, 2018 2:49 PM

Legacy UI Framework.

I have added below code in cshtml for generating query but still it required to configure queryin properties window,

 <script type="text/javascript">
        Coveo.$(function() {
            Coveo.$('#@Model.Id').on("buildingQuery", function(e, args) {
                args.queryBuilder.advancedExpression.add('@(Model.ToCoveoFieldName("advocacytableofcontents")) == "@fieldValue"');
                args.queryBuilder.advancedExpression.add('@(Model.ToCoveoFieldName("content id")) <> "@contentID"');
            }).coveoForSitecore('init', CoveoForSitecore.componentsOptions);
        });
    </script>
1 Reply
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Mar 21, 2018 3:25 PM

When adding a Legacy UI Coveo Search View from the Sitecore Experience Editor, it automatically opens the "Rendering Parameters" editor to edit the rendering itself.

All Coveo for Sitecore UI components also support being configured by data source items instead of rendering parameters.

You could prepare a Content Tree item with the default queries and properties.

What you could do when inserting a new Coveo Search View rendering is:

  1. Always click OK in the rendering parameters dialog. (This saves the component and replace the `$GenerateNewUniqueId` token by a real unique ID).
  2. In the Sitecore Content Tree, duplicate/clone the item with the default queries. Change the Unique ID field value for this item to have a different unique ID.
  3. Select the newly inserted component.
  4. Click the "More" menu in its floating toolbar.
  5. Click "Edit component properties".
  6. In the "Data source" field, click browse.
  7. Select the newly duplicated/cloned item from the Content Tree.
  8. Click OK in all the dialogs.
  9. Save the page.

Your component will now read its parameters from the data source item instead of its rendering parameters.

Ask a question