THIS IS ARCHIVED DOCUMENTATION

Setting Up External Sources Programmatically Using the Coveo for Sitecore Legacy Search UI Framework jQuery Plugin

Coveo for Sitecore 4.1 (November 2018)

Coveo for Sitecore allows you to perform search queries on content that’s external to Sitecore. It’s also possible to configure it directly from the Sitecore user interface as described in Displaying External Content in a Search Interface. However, it may be useful to specify the list of external sources to include programmatically. One way to do it’s to use the coveoForSitecore jQuery plugin.

  1. Set up the external source as explained in Configuring an External Source. Keep the name of the source handy as you’ll need it further in the procedure.

    Don’t set the external source on the search component as it will be set programmatically instead.

  2. Open the CoveoSearch.ascx file that’s located under the layouts/Coveo folder of your Sitecore instance.
  3. Add your external source to the list of external sources by adding this code snippet:

     Coveo.$(function() {
         CoveoForSitecore.componentsOptions = <%= Model.GetJavaScriptInitializationOptions() %>;
    
         // ADDED CODE -->
         CoveoForSitecore.componentsOptions.externalSources.push('[THE SOURCE NAME]');
         // <-- ADDED CODE
     });
    
  4. Coveo for Sitecore (July 2016) 

    The filter expression should also be modified to ensure that the content from the external source can be returned. You can alter the filter expression by adding this code snippet.

     Coveo.$(function() {
         CoveoForSitecore.componentsOptions = <%= Model.GetJavaScriptInitializationOptions() %>;     
         CoveoForSitecore.componentsOptions.externalSources.push('[THE SOURCE NAME]');  
         // ADDED CODE -->
         var originalFilterExpression = CoveoForSitecore.componentsOptions.filterExpression;
         CoveoForSitecore.componentsOptions.filterExpression = '(' + originalFilterExpression + ' OR @syssource=="[THE SOURCE NAME]")';
         // <-- ADDED CODE
     });
    
  5. Reload the search page. It should now include results from the external source.

    Let’s say you created a source in the Coveo Administration Console named John West Blog because you want to index this blog content to make it searchable in your website.

    The coveoSearch.ascx file should contain the following in the Coveo.$ function:

     Coveo.$(function() {
         CoveoForSitecore.componentsOptions = <%= Model.GetJavaScriptInitializationOptions() %>;
          // ADDED CODE -->
         CoveoForSitecore.componentsOptions.externalSources.push('John West Blog');  
         var originalFilterExpression = CoveoForSitecore.componentsOptions.filterExpression;
         CoveoForSitecore.componentsOptions.filterExpression = '(' + originalFilterExpression + ' OR @syssource=="John West Blog")';
         // <-- ADDED CODE
     });
    

    And when you perform a search, content from the blog should appear in your search results: