Insights

8 steps for limiting Coveo search results in a Sitecore multi-site implementation

June 16, 2016

I’ve come across the following requirement while working with Sitecore multi-site implementations over the years:

I have Sitecore with a multi-site implementation, Coveo is being used as the search engine, and I would like to limit the search results based on each site’s content. How can I do that?

Fortunately, this is quite straightforward to setup.

Here are 8 steps for limiting Coveo search results for sites in a Sitecore multi-site implementation.

1. You need a consistent content structure. 

Here is a suggestion for a content pattern you can use:

Site A

Home

Search-Results

SiteA-PageA

SiteA-PageB

Site B

Home

Search-Results

SiteB-PageA

SiteB-PageB

In this content structure note that for every site you have a Home, and each Home item has a Search-Results child item. The Site-Page items are just content you can use for your tests. In this case both "Search-Results" items should use the same template as well.

2. Update the Search-Results template and add a CoveoSearchResults sublayout as well as the Coveo Search Resources to the presentation details.

If you have created a custom CoveoSearchResults sublayout use that. This is most recommended, because if customizations are needed for that sublayout you won’t break Coveo’s upgrade path. If you have not created a custom CoveoSearchResults sublayout, use the CoveoSearchResults sublayout that comes with the Coveo for Sitecore installer.

3. Create a custom Sitecore rule that points to a specific type, as in the example below:

Coveo limiting search multisite - ONE.png

4. Use the code below as the rule definition.

This code is pretty straight forward.

What this is doing is setting the context of the search on the constructor of the class. This is done basically by using the current item (in this case, the Search-Results page, as we defined the rule on this item) and getting what the parent item is.

If you are following the content tree example of step 1, you will see that the parent item is Home. So when the code of the example runs, it will get the Home item ID and set it on the property ItemId. You can think of the following code like this “I am on Site A, or B and I’m setting the root item as the Home item of this very site. Limit the search for this item and it’s descendants”:

002.png

5. On the standard values of the Search-Results template, open the presentation details and edit the CoveoSearchResults sublayout.

6. On the "Filter expression rules" field click on Edit Rule, add the custom rule you just created. You should see a screen like the example below. Don't forget to save it:

003.png

7. Rebuild Coveo indexes.

8. Open the search-results on both sites and you’ll see that the content has been limited on each site.

Meet The Challenges Of Today's Digital Economy

Ready to take that first step and rise to your digital potential? Contact Valtech today.
Talk to us