THIS IS ARCHIVED DOCUMENTATION

Performing Search Queries when Indexing Page Content

Coveo for Sitecore (January 2017) Coveo for Sitecore (November 2018)

With the HTMLContentInBodyWithRequest or the FetchPageContent processor active, Coveo for Sitecore performs additional web requests when indexing Sitecore items to get the item page content, which is essentially the item as seen by a visitor (see Creating an HTML Representation of Page Content). A layout may contain search-driven components that can send a lot of unnecessary search queries to the search index.

In the January 2017 release of Coveo for Sitecore, a protection was introduced to prevent search queries when visiting items in order to populate the Quick view. Since indexing is performed in the background, an administrator might not be aware of the thousands of search requests that are sent to the search index. Such a heavy workload could negatively impact response times.

Before allowing search queries for the Quick view, ensure that the search-driven rendering output is really relevant in the Quick view and the full-text search. Consider other alternatives , such as:

To allow the LINQ queries in a search-driven component, you must:

  1. Allow the search queries at the index level in the configuration file.
  2. Allow the search query at the search context level.

Having two settings gives you greater control over which search queries are allowed and which are denied. You could use the setting at the search context level to allow search queries in Quick view only for specific search-driven components.

Step 1: Allowing Search Queries at the Index Level

This setting acts as a master switch. If the setting is set to false, the search queries are never executed in the context of the Quick view.

  1. Open the Coveo.SearchProvider.Custom.config file. It’s usually located under <SITECORE_INSTANCE_ROOT>\Website\App_Config\Include\Coveo.
  2. In the <defaultIndexConfiguration> element, add the following snippet.

     <queryConfiguration>
       <allowQueriesFromQuickView>true</allowQueriesFromQuickView>
     </queryConfiguration>
    
  3. Save and close the file.

Step 2: Allowing Search Queries at the Search Context Level

When using the Search Provider API to perform search queries, a search context must be created. An option must be set on the context so the search query can be executed in the context of the Quick view.

In your LINQ query, add the following section:

// Allows queries to be executed in the Quick view context.
var coveoSearchContext = context as ICoveoSearchContext;
if (coveoSearchContext != null) {
    if (coveoSearchContext.SearchContextOptions == null) {
        coveoSearchContext.SearchContextOptions = new CoveoSearchContextOptions();
    }
    coveoSearchContext.SearchContextOptions.AllowQueryFromQuickView = true;
}

As such:

ISearchIndex index = ContentSearchManager.GetIndex("Coveo_web_index");
using (var context = index.CreateSearchContext()) {
    // Allows queries to be executed in the Quick view context.
    var coveoSearchContext = context as ICoveoSearchContext;
    if (coveoSearchContext != null) {
        if (coveoSearchContext.SearchContextOptions == null) {
            coveoSearchContext.SearchContextOptions = new CoveoSearchContextOptions();
        }
        coveoSearchContext.SearchContextOptions.AllowQueryFromQuickView = true;
    }
 
    // Perform the LINQ query here...
}