From 18898f0370aac53898cd67cc19051f4a5f3debe2 Mon Sep 17 00:00:00 2001 From: Paul Martin Date: Fri, 2 Jun 2023 16:48:03 -0400 Subject: [PATCH] Issue 110: Call Sitecore API to get index field name instead of defaulting to a text field --- .../SynthesisSolrFieldNameTranslator.cs | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/Source/Synthesis.Solr/ContentSearch/SynthesisSolrFieldNameTranslator.cs b/Source/Synthesis.Solr/ContentSearch/SynthesisSolrFieldNameTranslator.cs index f81be24..a2e7583 100644 --- a/Source/Synthesis.Solr/ContentSearch/SynthesisSolrFieldNameTranslator.cs +++ b/Source/Synthesis.Solr/ContentSearch/SynthesisSolrFieldNameTranslator.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using System.Linq; using System.Reflection; using Sitecore; @@ -28,13 +29,14 @@ public SynthesisSolrFieldNameTranslator(SolrFieldMap solrFieldMap, SolrIndexSche } - public override string GetIndexFieldName(string fieldName) - { - if (_schema != null && (_schema.FindSolrFieldByName(fieldName) != null || _schema.SolrDynamicFields.Any(x => fieldName.EndsWith(x.Name.Substring(1))))) - return fieldName; - //at this point we can't be sure what type the data is in the field, our best bet would be a text field. - return AppendSolrText(fieldName); - } + public override string GetIndexFieldName(string fieldName) + { + if (_schema != null && (_schema.FindSolrFieldByName(fieldName) != null || _schema.SolrDynamicFields.Any(x => fieldName.EndsWith(x.Name.Substring(1))))) + return fieldName; + + // Let default Sitecore API try to resolve it + return base.GetIndexFieldName(fieldName, (CultureInfo)null); + } public override string GetIndexFieldName(MemberInfo member) { @@ -64,12 +66,12 @@ protected virtual string PreProcessSynthesisFieldName(string fieldName) /// the initial field name /// field name with a dynamic field identifier on it private string AppendSolrText(string fieldName) - { - if (Context.Site == null || Context.Language.Name == Context.Site.Language) - fieldName += "_t"; - else - fieldName += "_t_" + Context.Language; - return fieldName; - } - } + { + if (Context.Site == null || Context.Language.Name == Context.Site.Language) + fieldName += "_t"; + else + fieldName += "_t_" + Context.Language; + return fieldName; + } + } }