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:
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?
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.ProductModel
name.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.