June 16, 2016
I’ve come across the following requirement while working with Sitecore multi-site implementations over the years:
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.
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.
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.
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”: