Monday, August 27, 2018

Creating the Sitecore 9 SXA search component indexes

I recently started playing around with SXA for the first time to prepare for an upcoming SXA project. I love the concept and implementation. Unfortunately I had a problem getting the search components working - they were added to the page just fine, but no results showed.

The problem


In my browsers network tab I could see that the API returned status 400: "Object reference not set to an instance of an object".

In my log files I could find some further info:

7248 10:19:18 WARN Results endpoint exception
Exception: System.NullReferenceException
Message: Object reference not set to an instance of an object.
Source: Sitecore.ContentSearch.SolrProvider
at Sitecore.ContentSearch.SolrProvider.SolrFieldNameTranslator.StripKnownCultures(String fieldName)
at Sitecore.ContentSearch.SolrProvider.SolrFieldNameTranslator.StripKnownExtensions(String fieldName)
at Sitecore.ContentSearch.SolrProvider.SolrFieldNameTranslator.ProcessFieldName(String fieldName, String fieldTypeKey, Type returnType, CultureInfo culture, String returnTypeString, Boolean aggressiveResolver)
at Sitecore.ContentSearch.SolrProvider.SolrFieldNameTranslator.GetIndexFieldName(MemberInfo member, CultureInfo culture)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.VisitItemProperty(MemberExpression expression)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.VisitBinary(BinaryExpression expression)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.VisitBinary(BinaryExpression expression)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.VisitWhereMethod(MethodCallExpression methodCall)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.VisitWhereMethod(MethodCallExpression methodCall)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.VisitWhereMethod(MethodCallExpression methodCall)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.VisitWhereMethod(MethodCallExpression methodCall)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.VisitCountMethod(MethodCallExpression methodCall)
at Sitecore.ContentSearch.Linq.Parsing.ExpressionParser.Parse(Expression expression)
at Sitecore.XA.Foundation.Search.Spatial.GenericQueryable`2.GetQuery(Expression expression)
at Sitecore.ContentSearch.Linq.Parsing.GenericQueryable`2.Execute[TResult](Expression expression)
at Sitecore.XA.Feature.Search.Controllers.SearchController.GetResults(String v, String q, String s, String l, String g, String o, Int32 e, Int32 p, String sig, String site, String itemid)
Not terribly informative. I tried checking whatever relevant resources I could find on setting up SXA and search, such as setting_up/sxa_searchconfiguring/configure_sxa_indexing, and the SXA installation guide but all with no luck.

The solution

The solution is actually quite simple - the indexes aren't created automatically during installation and must be manually created. Easy peasy - once you think of it.
I'm unsure of the "right" way to do this, since it's not documented, but what I did was these simple steps:

  1. Go to [solrpath]\server\solr and copy [mysitename]_master_index folder, name it sitecore_sxa_master_index
  2. Go into that folder, open core.properties and replace [mysite]_master_index to sitecore_sxa_master_index
  3. Delete the data folder
  4. Repeat steps 1-3 for web
  5. Restart the solr service
  6. Reindex the 2 new indexes from the controlpanel
This fixed my issues and search worked beautifully.

I posted on the Sitecore #sxa Slack that I believed this documentation was missing - and was later asked for a solution, so I thought I'd post it here as well, to help others find it.

Next version of SXA is supposed to automatically install these cores if you use SIF install.