2

I need to update Solr schema for text highlighting using code.

What is the way to update Solr schema using code in Sitecore 10.3?

Since 'SolrProvider.GetHelper is obsolete'

1 Answer 1

5

It's all described in Sitecore documentation here:

https://doc.sitecore.com/xp/en/developers/103/platform-administration-and-architecture/add-custom-fields-to-a-solr-schema.html

In shortcut:

  • You need to create your own ISchemaPopulateHelper implementation, best by overriding SchemaPopulateHelper, e.g.
public class CustomPopulateHelper : SchemaPopulateHelper
{
    public CustomPopulateHelper(SolrSchema schema) : base(schema)
    {
    }
    ...
}
  • And your own factory like:
public class CustomPopulateHelperFactory : IPopulateHelperFactory
{
    public ISchemaPopulateHelper GetPopulateHelper(SolrSchema solrSchema)
    {
        return new CustomPopulateHelper(solrSchema);
    }
}
  • Then register the factory in patch file:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <contentSearch.PopulateSolrSchema>
        <processor type="Sitecore.ContentSearch.SolrProvider.Pipelines.PopulateSolrSchema.PopulateFields, Sitecore.ContentSearch.SolrProvider">
       <param type="Documentation.Examples.CustomPopulateHelperFactory, Documentation.Examples" patch:instead="*[@type='Sitecore.ContentSearch.SolrProvider.Factories.DefaultPopulateHelperFactory']"/>
     </processor>
      </contentSearch.PopulateSolrSchema>
    </pipelines>
  </sitecore>
</configuration>
2
  • It is helpful can you please suggest how can we get index name in this implementation Commented Aug 9, 2023 at 12:29
  • I answered your another question with detailed explanation. You can mark this answer as correct if it answered this question.
    – Marek Musielak
    Commented Aug 9, 2023 at 18:44

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.