Monday, February 6, 2017

Switching to Solr - trick with Global.asax

Hey ya!

In the web there are a lot of tutorials which can help you with switching indexes from Lucene to Solr. In most of them we have part where we need to edit Global.asax file and change inheritance to use IOC container. Here is the snippet from Sitecore documentation about which I am talking about. It is totally OK, but we have to keep in mind that method Application_Start from Global.asax.cs will not be triggered, so for instance when we want to register our custom routes in Global.asax.cs - we can't do it now. Now we should do it by usage pipelines etc

Workaround

There is smart workaraound which allow us to use Globax.asax.cs in traditional way. Instead changing inheritance within Global.asax, we can use approach presented below:

    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            var container = new WindsorContainer();
            
            try
            {

                //this line is crucial. it initialize IOC for Solr
                new Sitecore.ContentSearch.SolrProvider.CastleWindsorIntegration.WindsorSolrStartUp(container).Initialize();
            }
            catch (Exception ex)
            {
                Sitecore.Diagnostics.Log.Error("Solr init error", ex, this);
            }
        }
    }

In this code we've initialized IOC components for Castle Windsor to Solr and now it should work correctly.

It is worth to say that we can do it for other IOC Containers as well. We just have to use proper dll. More details about rest of components are in table.

See you soon!

Friday, February 3, 2017

Switching to Solr - Watch out!

I can bet that during switching from Lucene to Solr indexes you are using scripts to disable Lucene configs and enable Solr configs.

Am I right?

If yes, please be aware, because since Sitecore 8.2 we have additional config file related to Solr, it is called "Sitecore.ContentSearch.SolrCloud.SwitchOnRebuild.config" and your scripts can accidentally enable this config file on your environment, which is unnecessary for you until you don't use Solr Cloud.

During rebuilding my primary indexes, I was facing with HTTP ERROR 404 issues:

  • Problem accessing /solr/sitecore_master_index_rebuild/update
  • Problem accessing /solr/sitecore_web_index_rebuild/update
  • Problem accessing /solr/sitecore_core_index_rebuild/update

First strange thing which I saw, was the akward names of indexes. I've never seen "rebuild" in names of indexes, it was weird for me...

Solution

If you are facing with similar issue, please try disable Sitecore.ContentSearch.SolrCloud.SwitchOnRebuild.config. It helped for me and I hope that it will help for you!