1

I'm upgrading a Sitecore 9.3 solution to Sitecore 10.2. The solution uses Unicorn, Leprechaun, and Synthesis for ORM. As part of the upgrade, Synthesis was updated from 9.1.0.0 to 9.1.6.0.

Everything seems to work except for Synthesis SOLR search.

C#

using (var context = ContentSearchManager.CreateSearchContext(new SitecoreIndexableItem(settingContainer.InnerItem)))
{
    indexname = context.Index.Name;

    var hits = context.GetSynthesisQueryable<IStandardTemplateItem>()
                    .Where(x => x.AncestorIds.Contains(settingContainer.Id))
                    .Where(x => x.TemplateIds.Contains(settingTemplateID))
                    .GetResults()
                    .Hits;

    setting = hits.FirstOrDefault()?.Document;

    // 'setting' used to return a strongly typed implementation of the underlying item if available
    // so I could do this:
    var x = setting as ISiteHeaderItem
}

The setting variable now gets back a StandardTemplateItem object instead of the strongly typed object I used to get before the upgrade.

Digging through the Synthesis.Solr source code I found the spot where it should be mapping the search result to my strong type. Debugging with this leads to a confusing result:

debugging SynthesisSolrDocumentTypeMapper

Line 20 makes the call to the mapper which instantiates the strong type. However, it performs this mapping by reading the _template field of the document from the SOLR result. As you can see from the screenshot, there is no _template field.

Does anyone know why? And/or how to resolve this?

Things I have tried:

  • Re-Populated SOLR Managed Scheme
  • Re-Indexed all SOLR indexes
2
  • Assuming the documents do contain the _template field, is it possible the query no longer requests that field from Solr? Commented Jan 17, 2023 at 18:07
  • @MichaelWest Interesting. I compared the Search log files between 9.3 and 10.2. In 10.2 I see "fl=_name,url_t,__display_name_t,_uniqueid,_datasource,score" whereas in 9.3 it's just fl=*. The question is where is that configured?
    – sitecorepm
    Commented Jan 17, 2023 at 18:26

1 Answer 1

2

With the help of @MichaelWest and @benlipson I've identified the issue and have 2 solutions. Well really 1 workaround and 1 hack.

  1. (solution; actually this didn't fix it.. but good practice anyway) Ben pointed out that I was calling GetSynthesisQueryable<> with type IStandardTemplateItem for no good reason. Instead I refactored my code with generics so the actual Type I wanted back was used. This resolved the issue.

  2. (workaround) If you for some reason can't do this sort of refactor or your case is caused by something slightly different, try changing the ContentSearch.Solr.MaxNumberOfFieldsToProject setting to "0". This worked for me also.. but the refactor is definitely the preferred method.

  3. (hack) Another way to fix this is to modify the template that generates all your Synthesis models so that they each include a new property that maps to the _template index field. For example:

public interface IAlertsDictionaryItem : IStandardTemplateItem
{       
    [IndexFieldAttribute("_template")]
    ID Template { get; set; }
       
    // ...
}

public class AlertsDictionary : StandardTemplateItem, IAlertsDictionaryItem
{
    // ...

    [IndexFieldAttribute("_template")]
    public ID Template { get; set; }

    // ...
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.