0

It`s weird but I did not find any fieldtype for storage list of doubles/floats both in Sitecore and in Solr (I need this field just for storing, not for querieng).

Just need to store List< double> result of ComputedField in Solr.

I hope that many of you faced/solved this lack. Could you help me?

Sitecore 9.3 and Solr 8.8.1 if it is important.

1
  • 1
    what's wrong with the Number field type? – AJ - Jan 19 '20 at 10:43
4

Correct. Sitecore and Solr don't have a field type to map a collection or an array of doubles or floats.

These are the available multiValued field types automatically matched by Sitecore:

<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="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" />

You will need to implement the following steps to define a new custom multiValued field type for a double collection and apply it to your computed field:

  1. You need to define a new custom dynamicField in your index managed-schema.xml file:
<dynamicField name="*_tdm" type="pdouble" multiValued="true" indexed="true" stored="true"/>
  1. Then you will need to patch the typeMatches defined in the Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config to add a new custom typeMatch:
<typeMatch typeName="doubleCollection" type="System.Collections.Generic.List`1[System.Double]" fieldNameFormat="{0}_tdm" multiValued="true" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
  1. And finally you will need to use this new type in the definition of your computed field in the returnType property, in both following sections of your index configuration. For example:
<fields hint="raw:AddComputedIndexField">
  <field fieldName="myDoubleCollectionField" returnType="doubleCollection">MyAssembly.CustomComputedField,MyAssembly</field>
</fields>
<fieldNames hint="raw:AddFieldByFieldName">
  <field fieldName="myDoubleCollectionField" returnType="doubleCollection" />
</fieldNames>
2
  • 1
    Modifying the managed schema file is dangerous as it would get overwritten if the user populated the managed schema through the Sitecore Control Panel. Instead, you can add a processor to the contentSearch.PopulateSolrSchema pipeline that adds in the dynamic field, and then repopulate the managed schema. Here's one example of doing that. sitecoreblog.marklowe.ch/2018/10/customize-solr-managed-schema – Matthew FitzGerald-Chamberlain Jan 21 '20 at 15:06
  • Thank you Matthew for your addition! I totally agree and thank you for sharing it. – Alessandro Faniuolo Jan 21 '20 at 16:27

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.