Thursday, December 22, 2016

Configure solr for sitecore 8.1 initial version

Hi All,
     Today I am going to tell you about how to configure the Solr instead of lucene.
Here we using solr via Tomacat server. So these points I need to cover.
·         Install/Configure the tomcat
·         Install/Configure solr
·         Configure for sitecore

Install Tomcat:
1. Install Java jre from below URL:
http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html
2. Install Windows Service Installer for apache tomcat from below URL:
http://tomcat.apache.org/download-80.cgi
Note: Please select host manager option ticked and default location for tomcat is:
C:\Program Files\Apache Software Foundation\Tomcat 8.0
The default port used by Tomcat is 8080 (used to be 8983) but you may elect to use some other port. Don’t choose port 80.
Note: If you want run more then one tomcat on on system then use different connector port and shutdown port.
Eg: connector port: 8983, 8038, 8039 etc.
Shutdown port: 8005, 8025 etc.
3. Type configure tomcat and select automatic mode.
4. you can also select for alias name for tomacat by update in conf/server.xml in tomcat directory.
<Alias>tomcat</Alias>

Install Solr:
Download Solr 4.10.3 from http://lucene.apache.org/solr/downloads.html. Since we are installing on a Windows machine, you will want to get the .zip file version of the download.
Note: Archives for all past versions of Solr are available at the Apache archives.
1.   Extract the contents of the .zip to a temporary location of your choice.
2.   Find the \dist folder in the extracted solr-4.10.3 directory. Rename the solr-4.10.3.war to solr.war and copy the file to the Tomcat’s \webapps folder. The path in my environment was C:\Program Files\Apache Software Foundation\Tomcat 8.0\webapps.
3.   Create an empty Solr home folder. This will be the permanent place of residence on your machine for your Solr instance. For example, D:\solr is where I put my Solr instance.
4.   Find the \example\solr folder in the extracted solr-4.10.3 directory. Copy the contents of \example\solr to the empty Solr home folder you just created in step 4.
5.   Find the \example\lib\ext folder in the extracted solr-4.10.3 directory. Copy the contents of \example\lib\ext to Tomcat’s \lib folder. The path in my environment was C:\Program Files\Apache Software Foundation\Tomcat 8.0\lib.
6.   Set the home directory for Solr in Tomcat. This is done by adding a new Java option with the Monitor Tomcat program. In my case, the option was -Dsolr.solr.home=D:\solr
7.   Stop/start Tomcat and try browsing to your Solr instance. For example, http://tomcat:8983/solr.

Configure for Sitecore:
1.   Stop the Tomcat service.
2.   Go to the root of your Solr instance, in my case, D:\solr. We need to modify the "collection1" directory to serve as one of the cores (folders with config files and index data) required by Sitecore.
a.   Rename the folder to "sitecore_analytics_index"
b.   Inside the folder you will find a file called “core.properties” which you may edit with a text editor. You need to change the “name” value to the name of your core. For example, when I create the “sitecore_analytics_index” core, then I will edit the “core.properties” file to have the value name=sitecore_analytics_index

3.      Start the Tomcat service and visit the Solr administration page. You may need to reload your browser page if it was already up. Click on the “Core Admin” menu item. If you modified the old “collection1” core correctly you should now see a sitecore_analytics_index core.




4.   Stop the Tomcat service. Now we need to fix the schema of our “sitecore_analytics_index” core, otherwise Sitecore cannot parse the xml correctly. Edit the file at \sitecore_analytics_index\conf\schema.xml according to Sitecore’s knowledge base article: https://kb.sitecore.net/articles/227897. Don’t forget to define the field type for pint since we are using a version of Solr later than 4.9! Start Tomcat and reload the Core Admin page.
5.   Next we must generate a new, Sitecore-specific schema. Sitecore provides a tool for this. Navigate to the Control Panel of your Sitecore instance. Look for the “Generate the Solr Schema.xml file” link and click it. Provide a path for the source and target files (they can’t be the same file.) Once you have generated your new schema, replace the old schema with it. Restart the Tomcat service and make sure the core loads correctly.
6.   A vanilla install of Sitecore 8 update 2 requires 13 cores to work correctly. So far we have one, but don’t despair, now that we have a generated a schema this process is much easier.  Essentially, we are going to use our sitecore_analytics_index core as a template to create the others. To do this:
a.   Copy the sitecore_analytics_index folder.
b.   Repeat steps 2a and 2b for each copy.
c.   When you are done, your Solr home folder should contain the following cores


d.   If you have done everything correctly you should be able to restart Tomcat and see all the cores listed above on the Core Admin page.
7.   Update (3-7-2015): I decided to create a PowerShell shortcut for this step. Save yourself time!

Still with me? Hang in there, we are halfway home! Next, we must tell Sitecore to start using Solr instead of Lucene. This is done by appending or removing “disabled” as an extension of a configuration file’s name.
a.   Config files to DISABLE:

\App_Config\Include\Sitecore.ContentSearch.Lucene.DefaultConfigurations.config.disabled
\App_Config\Include\Sitecore.ContentSearch.Lucene.Index.Analytics.config.disabled
\App_Config\Include\Sitecore.ContentSearch.Lucene.Index.Core.config.disabled
\App_Config\Include\Sitecore.ContentSearch.Lucene.Index.Master.config.disabled
\App_Config\Include\Sitecore.ContentSearch.Lucene.Index.Web.config.disabled
\App_Config\Include\Sitecore.ContentSearch.Lucene.Indexes.Sharded.Core.config.example (left as is)
\App_Config\Include\Sitecore.ContentSearch.Lucene.Indexes.Sharded.Master.config.example (left as is)
\App_Config\Include\Sitecore.ContentSearch.Lucene.Indexes.Sharded.Web.config.example (left as is)
\App_Config\Include\Sitecore.Marketing.Definitions.MarketingAssets.Repositories.Lucene.Index.Master.config.disabled
\App_Config\Include\Sitecore.Marketing.Definitions.MarketingAssets.Repositories.Lucene.Index.Web.config.disabled
\App_Config\Include\Sitecore.Marketing.Definitions.MarketingAssets.Repositories.Lucene.IndexConfiguration.config.disabled
\App_Config\Include\ContentTesting\Sitecore.ContentTesting.Lucene.IndexConfiguration.config.disabled
\App_Config\Include\FXM\Sitecore.FXM.Lucene.Index.DomainsSearch.config.disabled
\App_Config\Include\ListManagement\Sitecore.ListManagement.Lucene.Index.List.config.disabled
\App_Config\Include\ListManagement\Sitecore.ListManagement.Lucene.IndexConfiguration.config.disabled
\App_Config\Include\Social\Sitecore.Social.Lucene.Index.Master.config.disabled
\App_Config\Include\Social\Sitecore.Social.Lucene.Index.Web.config.disabled
\App_Config\Include\Social\Sitecore.Social.Lucene.IndexConfiguration.config.disabled

b.   Config files to ENABLE:

\App_Config\Include\Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config
\App_Config\Include\Sitecore.ContentSearch.Solr.Index.Analytics.config
\App_Config\Include\Sitecore.ContentSearch.Solr.Index.Core.config
\App_Config\Include\Sitecore.ContentSearch.Solr.Index.Master.config
\App_Config\Include\Sitecore.ContentSearch.Solr.Index.Web.config
\App_Config\Include\Sitecore.Marketing.Definitions.MarketingAssets.Repositories.Solr.Index.Master.config
\App_Config\Include\Sitecore.Marketing.Definitions.MarketingAssets.Repositories.Solr.Index.Web.config
\App_Config\Include\Sitecore.Marketing.Definitions.MarketingAssets.Repositories.Solr.IndexConfiguration.config
\App_Config\Include\ContentTesting\Sitecore.ContentTesting.Solr.IndexConfiguration.config
\App_Config\Include\FXM\Sitecore.FXM.Solr.Index.DomainsSearch.config
\App_Config\Include\ListManagement\Sitecore.ListManagement.Solr.Index.List.config
\App_Config\Include\ListManagement\Sitecore.ListManagement.Solr.IndexConfiguration.config
\App_Config\Include\Social\Sitecore.Social.Solr.Index.Master.config
\App_Config\Include\Social\Sitecore.Social.Solr.Index.Web.config
\App_Config\Include\Social\Sitecore.Social.Solr.IndexConfiguration.config

8.   So I know that last step was pretty tedious, but if you've made it this far then the rest will be easier. Download the Solr Support Package from Sitecore and extract the contents of the zip file.
9.   Copy the following DLLs from the Solr Support Package into the \bin folder of your Sitecore Instance [N.B.: Castle Windsor is my Inversion of Control preference as Glass also uses it. Aside from Castle Windsor, Sitecore supports AutoFac, Ninject, StructureMap, and Unity.]:

o    Castle.Facilities.SolrNetIntegration.dll
o    Microsoft.Practices.ServiceLocation.dll
o    Sitecore.ContentSearch.Linq.Solr.dll
o    Sitecore.ContentSearch.SolrProvider.CastleWindsorIntegration.dll
o    Sitecore.ContentSearch.SolrProvider.dll
o    SolrNet.dll

Update (3-3-2015): If you are upgrading from Sitecore 8 update 1, then you only need to replace Sitecore.ContentSearch.SolrProvider.XXXXXIntegration.dll with the latest version from the Solr Support Package. All other DLLs remain unchanged.


10.          Download the Nuget package for Castle Windsor. Unzip the package by renaming the extension from .nupkg to .zip and extracting its contents. Copy the Castle.Windsor.dll from \lib\net40-client to the \bin folder of your Sitecore instance.
11.          Repeat step 10 for the Castle.Core Nuget package. Copy the Castle.Core.dll from \lib\net40-client to the \bin folder of your Sitecore instance.
12.          Since we are going to use IoC, we need to make our Sitecore instance aware of it by replacing the Application directive in the global.asax file with the following:

<%@Application Language='C#' Inherits="Sitecore.ContentSearch.SolrProvider.CastleWindsorIntegration.WindsorApplication" %>

13.          In order for Sitecore to talk to Solr, we need to give it a URL. This setting is maintained in the Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config file (remember, your address may differ from mine):

<setting name="ContentSearch.Solr.ServiceBaseAddress" value="http://tomcat:8983/solr" />

14.          When you browse to your Sitecore site you won't encounter any yellow screens of death. If you see a YSOD complaining about "Connection error to search provider [Solr] : Unable to connect to [http://tomcat:8983/solr]" then you are likely either missing a core or made typo when creating one. Assuming you are error free, the final step is to re-index. Go to the Control Panel and look for the "Indexing manager" link. Select all indexes and click the "Rebuild" button.

Note: Might be you face conflict in Castle.core and Castle.windsor dll because there different-2 version used by solr and glassmapper so you need to update the assembly binding in web.config for overcome that issue as below:

<dependentAssembly>
        <assemblyIdentity name="Castle.Windsor" publicKeyToken="407dd0808d44fbdc" culture="neutral" />
        <bindingRedirect oldVersion="3.1.0.0-3.1.9.0" newVersion="3.3.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" culture="neutral" />
        <bindingRedirect oldVersion="3.1.0.0-3.1.9.0" newVersion="3.3.0.0" />
 </dependentAssembly>

References: