Skip to end of metadata
Go to start of metadata
Icon

There is an quicker and more intuitive procedure for Enterprise Edition clients (see Using Boosting or Filtering Rules on Coveo Components).

This procedure is addressed mostly at Free, Pro, or Pro Cloud Edition clients.

If you are an Enterprise Edition client, this procedure can help you define filters that content editors and marketers will not have access to.

The Coveo Search component offers a variety of rules to filter or boost your search results.

The defined rules are only applied to the search page containing the search component.

 

Contrary to the Enterprise Edition of Coveo for Sitecore, the Free, Pro, and Pro Cloud Editions do not allow you to add filter and boost expressions by using a point-and-click approach. Instead, you need to add them through code. Remember that Coveo for Sitecore has an embedded version of the JavaScript Search Framework V1, so it should not be difficult to implement such expressions.

Note:

Icon

Although the examples in this tutorial are based on a Jetstream Demo instance, you could easily adapt the provided code to your own data.

Adding a Filter Expression

A filter expression is used to filter search results based on certain conditions that you define. For example, you may want to only display items with a template equal to Flight.

  1. Open the code-behind file associated with the Coveo Search component using a text editor (CoveoSearch.ascx for ASP.NET and SearchView.cshtml for ASP.NET MVC).

    Icon

    Make sure that you duplicate the component before you modify its code-behind file. To learn how to do this, see Duplicating the Coveo Search Component.

  2. Locate the last script element. It should look like this:

  3. Between Coveo.$('#<%= Model.Id %>') and .coveoForSitecore('init', ...), insert the following statement:

  4. The complete code should look like this:

    Icon

    In a MVC view rendering, you need to replace <%= ToCoveoFieldName("templatename") %> by @(Model.ToCoveoFieldName("templatename")).

  5. Save the file.
  6. Reload your search interface in a web browser.
  7. Validate that only Flight items appear in your search results.

Adding a Boost Expression

A boost expression is used to modify the ranking of a particular subset of search results. It can be implemented in a way similar to filter expressions, except that you need to use a QRE instead. For example, if you would want Flight items with a Price field lower than 500$ to appear first in the list of search results, you would need to follow this procedure.

  1. Open the code-behind file associated with the Coveo Search component using a text editor (CoveoSearch.ascx for ASP.NET and SearchView.cshtml for ASP.NET MVC).

    Icon

    Make sure that you duplicate the component before you modify its code-behind file. To learn how to do this, see Duplicating the Coveo Search Component.

  2. Locate the last script element. It should look like this:

  3. Between Coveo.$('#<%= Model.Id %>') and .coveoForSitecore('init', ...), insert the following statement:

    Icon

    A modifier typically has a value comprised within the range [-100, 100]. A positive value means that the subset of search results matching your expression are boosted in your search results. A negative value means the opposite; they will end up closer to the end of the list.

  4. The complete code should look like this:

    Icon

    In a MVC view rendering, you need to replace <%= ToCoveoFieldName("templatename") %> by @(Model.ToCoveoFieldName("templatename")).

  5. Save the file.
  6. Reload your search interface in a web browser.
  7. Validate that only the cheapest flights (< $500) appear first in your search results.

What's Next?