12

Background: Sitecore 9, Solr 6.6.1

I have got a strange issue with incorrect resolution of field type by SOLR during item indexing.

I read the following article about resolution a field names:

https://doc.sitecore.net/sitecore_experience_platform/setting_up_and_maintaining/search_and_indexing/using_solr_field_name_resolution

There are two separate stages of resolution:

  • Field name resolution during indexing
  • Field name resolution during search

Field name resolution during indexing

As it is described in the documentation, Sitecore uses the AddFieldByFieldTypeName and AddTypeMatch sections of the configuration file for maping Sitecore field types to dynamic field types.

The default definition of AddFieldByFieldTypeName section of Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config:

<fieldTypes hint="raw:AddFieldByFieldTypeName">            
   <!-- Skipped some rows as it doesn't matter in my case -->       
   <fieldType fieldTypeName="checklist|multilist|treelist|tree list|treelistex|tree list|multilist with search|treelist with search" returnType="stringCollection" />
   <fieldType fieldTypeName="name lookup value list|name value list" returnType="stringCollection" />
   <fieldType fieldTypeName="droplink|droptree|grouped droplink|tree" returnType="stringCollection" />
</fieldTypes>

I have a field ProductModel with Droptree type in Sitecore. As we can see it has to be associated with stringCollection type.

Let's look further. The default definition of AddTypeMatch section:

<typeMatches hint="raw:AddTypeMatch">
    <typeMatch typeName="guidCollection" type="System.Collections.Generic.List`1[System.Guid]" fieldNameFormat="{0}_sm" multiValued="true" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
    <typeMatch typeName="textCollection" type="System.Collections.Generic.List`1[System.String]" fieldNameFormat="{0}_txm" multiValued="true" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
    <typeMatch typeName="stringCollection" type="System.Collections.Generic.List`1[System.String]" fieldNameFormat="{0}_sm" multiValued="true" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
    <typeMatch typeName="intCollection" type="System.Collections.Generic.List`1[System.Int32]" fieldNameFormat="{0}_im" multiValued="true" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
    <typeMatch typeName="guid" type="System.Guid" fieldNameFormat="{0}_s" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
    <typeMatch typeName="id" type="Sitecore.Data.ID, Sitecore.Kernel" fieldNameFormat="{0}_s" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
    <typeMatch typeName="shortid" type="Sitecore.Data.ShortID, Sitecore.Kernel" fieldNameFormat="{0}_s" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
    <typeMatch typeName="string" type="System.String" fieldNameFormat="{0}_s" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
    <typeMatch typeName="text" type="System.String" fieldNameFormat="{0}_t" cultureFormat="_{1}" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
    <typeMatch typeName="int" type="System.Int32" fieldNameFormat="{0}_tl" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
    <typeMatch typeName="bool" type="System.Boolean" fieldNameFormat="{0}_b" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
    <typeMatch typeName="datetime" type="System.DateTime" fieldNameFormat="{0}_tdt" format="yyyy-MM-dd'T'HH:mm:ss.FFF'Z'" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
    <typeMatch typeName="long" type="System.Int64" fieldNameFormat="{0}_tl" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
    <typeMatch typeName="float" type="System.Single" fieldNameFormat="{0}_tf" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
    <typeMatch typeName="double" type="System.Double" fieldNameFormat="{0}_td" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
    <typeMatch typeName="stringArray" type="System.String[]" fieldNameFormat="{0}_sm" multiValued="true" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
    <typeMatch typeName="intArray" type="System.Int32[]" fieldNameFormat="{0}_im" multiValued="true" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
    <typeMatch typeName="datetimeArray" type="System.DateTime[]" fieldNameFormat="{0}_dtm" multiValued="true" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
    <typeMatch typeName="datetimeCollection" type="System.Collections.Generic.List`1[System.DateTime]" fieldNameFormat="{0}_dtm" multiValued="true" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
    <typeMatch typeName="coordinate" type="Sitecore.ContentSearch.Data.Coordinate, Sitecore.ContentSearch.Data" fieldNameFormat="{0}_rpt" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
</typeMatches>

We can see that the field which was associated with type stringCollection should have the fieldNameFormat="{0}_sm" format.

BUT, when I look in the index, the field has "{0}_s" format and looks like:

"productmodel_s":"b1550b9524e64d03a7f2b472dad5cd53"

This is the key point in my problem! because when I try to build facet based on this field:

ContentSearchManager.GetIndex("sitecore_web_index").CreateSearchContext().GetQueryable<SearchResultItem>().FacetOn(item => item["productmodel"]).GetResults();

my query looks like:

Solr Query - ?q=(*:*)&rows=2147483647&fq=_indexname:(sitecore_web_index)&fq=(_language:(en*))&facet=true&facet.field=productmodel_sm&f.productmodel_sm.facet.mincount=0&wt=xml

ProductModel field has productmodel_sm format and definitely Solr can't find this field and I don't get any facets.

The question is why the field name resolution is defined wrong during indexing?

  • _s suffix looks correct for Droptree field value as it is actually only one ID. I would check 'droptree' configuration on showconfig.aspx page – Daniil Nov 20 '17 at 11:27
  • @Daniil probably yes, but in accordance with a process of the field name resolution which described on the documentation, it should be _sm. Anyway, the name should be the same both during indexing and the search time. – Artsem Prashkovich Nov 21 '17 at 13:44
  • Does having more than one value for the ProductModel change the type it gets indexed as (*_sm instead of *_s)? I am just wondering if this is a bug where the converter is misinterpreting the type rather than taking it from the defined Field Type of the Sitecore field. – vandsh Dec 1 '17 at 14:49
  • @vandsh I know about issues that we can get if we have a few fields with the same name. It is the first what I checked and I don't have another filed with the ProductModel name. – Artsem Prashkovich Dec 6 '17 at 15:48
  • @ArtsemPrashkovich Sorry maybe I was unclear, I didn't mean fields named the same, I meant if you were to actually put multiple values into your Product Model field (rather than a single value in your example). My wild guess is that the field converter logic is picking it up a as a single string rather than multi-valued. – vandsh Dec 6 '17 at 16:17
9

Just ran into the same issue with a Droplink. This definitely seems like a bug.

My guess is that the indexing type is actually being set based on the return type of field reader associated with the field type:

<fieldReader fieldTypeName="droplink|droptree|grouped droplink|tree|reference" 
    fieldReaderType="Sitecore.ContentSearch.FieldReaders.LookupFieldReader, Sitecore.ContentSearch" />

I was able to work around the issue by patching the returnType to string:

<fieldType fieldTypeName="droplink|droptree|grouped droplink|tree" returnType="string" />
  • Had exact same problem. Definitely a bug or just a fail on Sitecore's part to get their default SOLR config correct. Can anyone think of a reason why it needs to be string and not id? All those fields ultimately contain links as guids so it seems like the right match. However maybe there are issues with blanks? Who knows, string works, though. – theyetiman Jul 25 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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