Product DocsMenu

Coveo Platform 7.0 >
Administrator Help > Coveo .NET Front-End 12.0 > Integrating a Search Interface in a Sitecore Website

Integrating the Coveo .NET Search Interface in a Sitecore Website

Integrating the Coveo .NET search interface into Sitecore allows your end-users to search your Coveo index content directly from your Sitecore website using a feature-rich Coveo search interface.

Note: If not already done, index the content of your Sitecore site so you can include it in the scope of the search interface to integrate to Sitecore (see Sitecore Connector).

To integrate the Coveo search interface in a Sitecore website

  1. Using an administrator account, log on to the Sitecore server.

  2. If not already done, install or update the Coveo search interfaces on the Sitecore server (see Installing Coveo .NET Front-End).

  3. Start the IIS Manager (on the Windows taskbar, select Start > Administrative Tools > Internet Information Services (IIS) Manager).

  4. In Internet Information Services (IIS) Manager, create a virtual directory for your Sitecore web application:

    1. In the Connections panel, expand to the root of your Sitecore web application, right-click it and select Add Virtual Directory

    2. In the Add Virtual Directory dialog box, enter Coveo in the Alias box and the [.Net_Front-End_Path]\Web\Coveo folder in the Physical path box.

  5. Using a text editor:

    1. Open the Sitecore web.config file.

      Note: It is recommended to make a backup of the web.config file before editing it.

    2. In the configuration\configSections section, add the following code:

      <sectionGroup name="coveoCnlWeb">
        <section name="customContent" type="System.Configuration.SingleTagSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </sectionGroup>
      <sectionGroup name="coveoEnterpriseSearch">
        <section name="database" type="System.Configuration.SingleTagSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        <section name="analytics" type="System.Configuration.SingleTagSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        <section name="locations" type="System.Configuration.SingleTagSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        <section name="server" type="System.Configuration.SingleTagSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </sectionGroup>
    3. In the configuration\system.web\pages section, add the following code:

      <controls>
        <add tagPrefix="cnla" namespace="Coveo.CNL.Web.Ajax" assembly="Coveo.CNL.Web, Version=12.0.0.0, Culture=neutral, PublicKeyToken=44110d16825221f2" />
        <add tagPrefix="cnlb" namespace="Coveo.CNL.Web.BetterControls" assembly="Coveo.CNL.Web, Version=12.0.0.0, Culture=neutral, PublicKeyToken=44110d16825221f2" />
        <add tagPrefix="cnlm" namespace="Coveo.CNL.Web.Misc" assembly="Coveo.CNL.Web, Version=12.0.0.0, Culture=neutral, PublicKeyToken=44110d16825221f2" />
        <add tagPrefix="cnlv" namespace="Coveo.CNL.Web.Validators" assembly="Coveo.CNL.Web, Version=12.0.0.0, Culture=neutral, PublicKeyToken=44110d16825221f2" />
        <add tagPrefix="cnlvs" namespace="Coveo.CNL.Web.Validators.ServerSide" assembly="Coveo.CNL.Web, Version=12.0.0.0, Culture=neutral, PublicKeyToken=44110d16825221f2" />
        <add tagPrefix="cnlw" namespace="Coveo.CNL.Web.Widgets" assembly="Coveo.CNL.Web, Version=12.0.0.0, Culture=neutral, PublicKeyToken=44110d16825221f2" />
        <add tagPrefix="ces" namespace="Coveo.CES.Web.Search.Controls" assembly="Coveo.CES.Web.Search, Version=12.0.0.0, Culture=neutral, PublicKeyToken=44110d16825221f2" />
        <add tagPrefix="cs" namespace="Coveo.CES.Web.Search.Controls.CustomerService" assembly="Coveo.CES.Web.Search, Version=12.0.0.0, Culture=neutral, PublicKeyToken=44110d16825221f2" />
      </controls>
      <namespaces>
        <add namespace="Coveo.CES.Web.Search" />
        <add namespace="Coveo.CNL.Web" />
      </namespaces>
    4. In the configuration\system.web\compilation section, add the following code:

      <assemblies>
        <add assembly="Coveo.CNL, Version=12.0.0.0, Culture=neutral, PublicKeyToken=44110d16825221f2" />
        <add assembly="Coveo.CNL.Web, Version=12.0.0.0, Culture=neutral, PublicKeyToken=44110d16825221f2" />
        <add assembly="Coveo.CES.Common, Version=12.0.0.0, Culture=neutral, PublicKeyToken=44110d16825221f2" />
        <add assembly="Coveo.CES.Web.Search, Version=12.0.0.0, Culture=neutral, PublicKeyToken=44110d16825221f2" />
      </assemblies>
    5. In the configuration section, add the following code:

      <coveoCnlWeb>
        <customContent uri="~/Coveo/" anonymousUri="~/Coveo/Anonymous/" />
      </coveoCnlWeb>
      <coveoEnterpriseSearch>
        <server hostname="localhost" port="52800" servicesHostname="localhost" servicesPort="52810" instance="default" mirrorName="default" sslCertificatePath="C:\Program Files\Coveo .NET Front-End 12\Web\certificate.p12" />
        <database enabled="false" connectionString="mongodb://localhost/databaseName" />
        <analytics enabled="false" connectionString="Data Source=yourServerName;Initial Catalog=CoveoAnalytics;Integrated Security=SSPI;" />
      </coveoEnterpriseSearch>
    6. Save the file.

  6. Integrate the search interface in a Sitecore layout or sublayout:

    • Add the following code at the appropriate location in the Sitecore .aspx layout or sublayout file in which you want to integrate the Coveo search interface control.

      <%@ Register TagPrefix="ces" Namespace="Coveo.CES.Web.Search.Controls" Assembly="Coveo.CES.Web.Search, Version=12.0.0.0, Culture=neutral, PublicKeyToken=44110d16825221f2" %>
      <%@ Assembly Name="Coveo.CNL, Version=12.0.0.0, Culture=neutral, PublicKeyToken=44110d16825221f2" %>
      <%@ Assembly Name="Coveo.CNL.Web, Version=12.0.0.0, Culture=neutral, PublicKeyToken=44110d16825221f2" %>
      
      <asp:Panel ID="pnResultsPanel" runat="server">
            <ces:SearchHub id="c" runat="server"/>
      </asp:Panel>

      OR

    1. When you chose to index Sitecore security using a security provider (see Configuring a Sitecore Security Provider topic in PDF), you must rather add the following code that includes a script to allow the search interface to display the search results corresponding to the currently logged on user.

      Using the Sitecore API, the c_OverrideUser script retrieves the currently logged on user and passes this user to the Coveo search Interface.

      Note: CES security elements are case sensitive. The Sitecore connector always indexes security elements in lower-case. Ensure to provide a lower-case username for the security to be resolved correctly.

      <%@ Control Language="C#" AutoEventWireup="true" Inherits="layouts_PFCEnergy_CoveoSearchResults" Codebehind="CoveoSearchResults.ascx.cs" %>
      <%@ Register TagPrefix="ces" Namespace="Coveo.CES.Web.Search.Controls" Assembly="Coveo.CES.Web.Search, Version=12.0.0.0, Culture=neutral, PublicKeyToken=44110d16825221f2" %>
      <%@ Assembly Name="Coveo.CNL, Version=12.0.0.0, Culture=neutral, PublicKeyToken=44110d16825221f2" %>
      <%@ Assembly Name="Coveo.CNL.Web, Version=12.0.0.0, Culture=neutral, PublicKeyToken=44110d16825221f2" %>
       
      <script runat="server">
      void c_OverrideUser(object p_Sender, Coveo.CES.Web.Search.Controls.OverrideUserEventArgs p_Args)
      {
        // The name of the security provider defined under the Admin Tool
        string securityProviderName = "Sitecore Security Provider";
        Coveo.CES.Web.Search.Providers.ICESUserIdentityFactory factory = Coveo.CES.Web.Search.Providers.SearchProviderFactory.CreateDefaultUserIdentityFactory();
        // Get the username from SitecoreAPI
        string userName = Sitecore.Context.GetUserName().ToLower();
        // Add to the collection of identities
        Coveo.CES.Web.Search.Providers.IUserIdentity user = factory.CreateSecurityProviderUser(userName, securityProviderName, false, null);
        p_Args.AdditionalIdentities.Add(user);
      }
      </script>
       
      <div id="contentMain">
        <asp:Panel ID="pnResultsPanel" runat="server">
          <ces:SearchHub id="c" runat="server" OnOverrideUser="c_OverrideUser"/>
        </asp:Panel>
      </div>

      Note: OnOverrideUser event is not available for all Coveo search controls such as QuickSearch and SearchBox controls.

      The search interface can target an explicit index source as shown in the following script.

      <script runat="server">
      override void OnInit(EventArgs p_Args)
      {
         SearchBinding.MainSearchObject.SetupSearchBuilder += this.Search_SetupSearchBuilder;
         base.OnInit(p_Args);
      }
      
      void Search_SetupSearchBuilder(object p_Sender, SetupSearchBuilderEventArgs p_Args)
      { 
          p_Args.Builder.AddConstantExpression("@Source=MySourceName");
      }
      </script>
  7. Using a browser, access the modified page to view the search hub.

    The Front-End Server Configuration first time setup page appears to allow you to complete the Coveo Front-End installation (see Coveo .NET Front-End First Time Setup).

Tip: If you notice that some of Coveo images or JavaScript are missing because they do not load in the search interface, you can fix this problem with a simple edit of the Sitecore web.config file (not the Coveo web.config file). In the file, locate the <setting name="IgnoreUrlPrefixes"...> tag and add the |/Coveo/ string to the value attribute.

Example:

<setting name="IgnoreUrlPrefixes" value="/sitecore/default.aspx|/trace.axd|/webresource.axd|/Coveo/"/>

What's Next?

Consider also integrating the Coveo search in the Sitecore Content Editor (see Integrating the Coveo .NET Search in the Sitecore Content Editor).

People who viewed this topic also viewed