Posts

Showing posts with the label fieldNameTranslator

Back to Basics: Fetch Solr Index Field Name for Sitecore Fields Using Solr FieldNameTranslator

Image
I have been meaning to write this post for a while as I have been using this nifty little feature in all my content search API implementations using the Solr provider. Unsafe: Defining SearchResultItem classes using hard coded Solr fields names for IndexField data annotation attributes as follows: [IndexField("page_title")] public string PageTitle { get; set; }   Problems : Cause runtime errors when field names change in Sitecore Hard coded strings, sort of magic values Unmanageable code Safe: Define SearchResultItem classes using strongly typed constants for data annotation attributes as follows: [IndexField(SampleItem.PageTitleSolrIndexFieldName)] public string PageTitle { get; set; } Solution : Compile time errors are way better than runtime errors More manageable code More readable code More dynamic query building Trick : Fetch Solr translated field name values on template fields  using  FieldNameTranslator  and reference them  with code gener

RESOLVED: Sitecore Solr provider error: Value cannot be null. Parameter name: fieldNameTranslator.

Server Error in '/' Application. Value cannot be null. Parameter name: fieldNameTranslator Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentNullException: Value cannot be null. Parameter name: fieldNameTranslator Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [ArgumentNullException: Value cannot be null. Parameter name: fieldNameTranslator]    Sitecore.ContentSearch.Linq.Solr.SolrIndexParameters..ctor(IIndexValueFormatter valueFormatter, IFieldQueryTranslatorMap`1 fieldQueryTranslators, FieldNameTranslator fieldNameTranslator, IExecutionContext[] execut