Thursday, February 15, 2018

Getting SXA to work with Solr in Sitecore 9

When I started working with Sitecore 9 (initial release) and SXA 1.5.

I followed the instructions for installing Sitecore 9 and then Sitecore Powershell extension 4.7 and SXA 1.5.
I started exploring and everything seemed to work fine until I started working with page list and search components. These components need item query / search scope to be able to retrieve items based on certain query.
I was able to build the item query and go the results in the CM environment but when I publish the pages and load these pages, queries never returned anything.
Tried re-indexing, re-publishing but doesn't seemed to work.
Finally #Slack came to the rescue.

Here are couple of things that worked for me.
Fix 1
In Sitecore 9 initial release you need to enable one of the configuration file under Include\z.Foundation.Overrides depending on your search platform you are using. In my case it was Solr and hence I had to enable Sitecore.XA.Foundation.Search.Solr.config.
But enabling this caused my Solr master and web indexes failed to build and even the schema was not getting populated (Control Panel -> Populate Solr Schema).
Having no clue, someone in the slack #sxa channel mentioned that Sitecore 9 initial release have an issue in the above file. You need to remove the $id from the core and put the actual core name for your solr indexes. In my case it was xp1_master_index and xp1_web_index.
The changed configuration in Sitecore.XA.Foundation.Search.Solr.config is shown below with highlighted section

     
        
          
            
            Sitecore.XA.Foundation.Search.Providers.Solr.SolrSearchIndex, Sitecore.XA.Foundation.Search.Providers.Solr
            xp1_master_index 
            
              
                Sitecore.XA.Foundation.VersionSpecific.Search.ItemCrawler, Sitecore.XA.Foundation.VersionSpecific
              
            
          
          
            
            Sitecore.XA.Foundation.Search.Providers.Solr.SolrSearchIndex, Sitecore.XA.Foundation.Search.Providers.Solr
            xp1_web_index 
            
              
                Sitecore.XA.Foundation.VersionSpecific.Search.ItemCrawler, Sitecore.XA.Foundation.VersionSpecific
              
            
          
        
      

Fix 2
Una Vanhoeven also suggested to add couple of dynamic fields in Solr for master and web cores. Her blog explains it very well and hence not going to add same steps here.. Link to her blog

Once you are done with above two fixes, rebuild master index, re-publish and re-build web index. Now not only your master and web indexes will get built properly, your SXA components will also start working

Hope this helps