Setting up indexes for multi-site Sitecore

When you  start working on multi-sites project ,one of the things will come cross your mind is indexing, and do we really need one index or it is better to have multi indexes.

I was working on 16 websites running on one Sitecore instance, actually those websites are using different content,  so each website has its own content,  I have only custom dictionary items shared between all the sites for labels, i am using default Sitecore index for them, in the beginning i was thinking to use the out of the box indexes from Sitecore, this will work fine and without no issue, but i have many  listing pages, and i am using search to retrieve data, lets say i want to retrieve data for website1 why should i go to the default index to retrieve only data for the current site.

so i decided to have separate index for each site, and i will use the default index for only shared content like the custom dictionaries that i have, and this will improve the performance for the websites.

  1. Leave sitecore default indexes as is (sitecore_web_index, sitecore_master_index and sitecore_core_index)
  2. I was using SOLR as search engine, so if you are using solr you need to create two cores for each website, one for master one for web, with this format, [websitename]_[databasename]_index, so later we can write general code to read the index ,  Example for Website1 : website1_master_index and website1_web_index, website name is same website name in sitedefintion.config
  3. For each site, duplicate the configuration for sitecore_master_index and sitecore_web_index and set the content root for each site.
  4. To do that take copy of Sitecore.ContentSearch.Solr.Index.Master.config, and rename it to WebsiteName.ContentSearch.Solr.Index.Master.config, and take copy of Sitecore.ContentSearch.Solr.Index.Web.config and rename it to WebsiteName.ContentSearch.Solr.Index.Web.config, duplicate these configurations for each website.

WebsiteName.ContentSearch.Solr.Index.Master.config should look like this :

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
 <sitecore>
 <contentSearch>
 <configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
 <indexes hint="list:AddIndex">
 <index id="websitename_master_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
 <param desc="name">$(id)</param>
 <param desc="core">$(id)</param>
 <param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" />
 <configuration ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration" />
 <strategies hint="list:AddStrategy">
 <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/syncMaster" />
 </strategies>
 <locations hint="list:AddCrawler">
 <content type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
 <Database>master</Database>
 <Root>/sitecore/content/websitename</Root>
 </content>
 <media type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
 <Database>master</Database>
 <Root>/sitecore/media library/websitename</Root>
 </media>
 </locations>
 </index>
 </indexes>
 </configuration>
 </contentSearch>
 </sitecore>
</configuration> 

WebsiteName.ContentSearch.Solr.Index.Web.config should look like this :

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
 <sitecore>
 <contentSearch>
 <configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
 <indexes hint="list:AddIndex">
 <index id="websitename_web_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
 <param desc="name">$(id)</param>
 <param desc="core">$(id)</param>
 <param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" />
 <configuration ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration" />
 <strategies hint="list:AddStrategy">
 <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/onPublishEndAsync" />
 </strategies>
 <locations hint="list:AddCrawler">
 <content type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
 <Database>web</Database>
 <Root>/sitecore/content/websitename</Root>
 </content>
 <media type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
 <Database>web</Database>
 <Root>/sitecore/media library/websiename</Root>
 </media>
 </locations>
 </index>
 </indexes>
 </configuration>
 </contentSearch>
 </sitecore>
</configuration> 

To get your search index for context website, you just need this code :

protected ISearchIndex SearchIndex
 {
 get
 {
 return ContentSearchManager.GetIndex(
 string.Format("{0}_{1}_index", Sitecore.Context.Site.Name.ToLower(),
 Sitecore.Context.Database.Name));
 }
 }

 

I hope you find this post helpful, If you have any additional knowledge on this subject, comments or questions, please let me know in the comments section below.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s