Coveo on a Sitecore multi-site implementation: 8 steps on how to limit the search results for each site

Working with Sitecore multi-sites implementation these last years I have come across a requirement like this and I decided to write a post about it:
I have a Sitecore with a multi-site implementation and has Coveo as the search engine and I would like limit the search results per site’s content. How can I do that?
Fortunately this is quite straight forward to setup. Here are 8 steps on how you can do that.
1 – You need a consistent content structure.  Here is a suggestion of a content pattern you can use:
Site A
Site B
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 test. In this case both “Search-Results” items should use the same template as well.
2. Update the Search-Results template and add to the presentation details a CoveoSearchResults sublayout as well as the Coveo Search Resources. If you have created a custom CoveoSearchResults use that. This is most recommended as if customizations are needed for that sublayout you don`t break Coveo`s upgrade path. If not 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 bellow:


4. On the constructor of the class set the code bellow. Note that this code looks for the context item(in this case the Search-Results page) and set what the parent item ID is. This is what is limiting the context of the search. You can think of this 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”.


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 and you should see a screen like the example bellow. Don’t forget to save it:


7. Rebuild Coveo indexes.
8. Open the search-results on both sites and see the content limited for each site.

Click here to see it in portuguese


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s