Gravatar for dean_thrasher@epam.com

Question by Dean Thrasher, Jul 7, 2016 11:11 AM

Configuring number fields in Coveo for Sitecore v4

We’re having some trouble configuring Coveo to handle fields with decimal or float values. For example, fields like Price or Average Rating in the Sitecore Reference Storefront. By default, all values are being treated like strings. Could you provide us with an example of how to configure a regular field and a computed field of this type?

In particular, we want to allow fields like Price and Average Rating to be facetable and sortable. Both fields in the reference storefront contain values like 5.99 or 2.3.

We have looked at the following help pages on the Coveo site, but seem to be missing a step somewhere.

  • https://developers.coveo.com/display/public/SitecoreV4/Creating+a+Computed+Date+Field
  • https://developers.coveo.com/display/public/SitecoreV4/Creating+a+Computed+Field+for+a+Referenced+Item

Do we need to add the returnType=”Number” attribute to the computed field in the configuration file AND set the value of the ReturnType property to “Number” within the IComputedIndexField class?

Could this problem also have to do with the fact that Sitecore has created custom field types for these fields?

  • AdjustedPrice is a “Commerce Decimal Control” with cstypename=”Currency”
  • CustomerAverageRating is a “Commerce Single Control” with cstypename=”Double”

The Lucene configuration for these fields is mapped to System.Double and System.Single respectively.

1 Reply
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Jul 7, 2016 2:50 PM

Hi Dean,

This is a very good question. I have no experience with Sitecore Commerce or Sitecore Reference Storefront.

I looked at the Storefront include files ans I saw they have a patch file to modify settings for the default Lucene index configuration and also an example for SOLR.

https://github.com/Sitecore/Reference-Storefront/blob/master/Storefront/AX/CSF/App_Config/Include/Reference.Storefront/Reference.Storefront.Index.Lucene.config

The content of this file told me the fields were supposed to already exist and were only patched here. This led me to the "Sitecore Commerce Connect" and "Sitecore Commerce Server Connect" packages that are prerequisites to the "Sitecore Reference Storefront". Both have their own Lucene default index configuration patch files to add new field types, new computed index fields and new field configurations.

In order to switch a Sitecore Commerce solution indexing platform from Lucene to Coveo, you would have to create similar patch files to convert all the Lucene configurations to Coveo configurations for all the solution levels ("Sitecore Commerce Connect", "Sitecore Commerce Server Connect", and "Sitecore Reference Storefront").

For your specific question, I guess "AdjustedPrice" and "CustomerAverageRating" are fields already defined in a Sitecore template item. So there is no need to create computed index field for those. Their type are simply not correct in the Coveo index due to missing configuration.

I found this section in the CommerceServer.Index.Lucene.config file:

<fieldTypes hint="raw:AddFieldByFieldTypeName">
  <fieldType fieldTypeName="commerce decimal control" type="System.Double" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" boost="1f" vectorType="NO" indexType="TOKENIZED" storageType="NO" />
  <fieldType fieldTypeName="commerce single control" type="System.Single" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" boost="1f" vectorType="NO" indexType="TOKENIZED" storageType="NO" />
  ...
</fieldTypes>

This configures the Lucene default index configuration on how to treat fields of those types. There are 14 field types in this section.

I'm not sure if Coveo index configuration supports the <fieldTypes hint="raw:AddFieldByFieldTypeName"> section but if it does, here's how you would need to configure the fields:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <coveo>
      <defaultIndexConfiguration>
        <fieldMap>
          <fieldNames hint="raw:AddFieldByFieldName">
            <fieldType fieldName="adjustedprice" isFacet="true" isSortable="true" settingType="Coveo.Framework.Configuration.FieldConfiguration, Coveo.Framework" />
            <fieldType fieldName="customeraveragerating" isFacet="true" isSortable="true" settingType="Coveo.Framework.Configuration.FieldConfiguration, Coveo.Framework" />
            ...
          </fieldNames>
          <fieldTypes hint="raw:AddFieldByFieldTypeName">
            <fieldType fieldTypeName="commerce decimal control" type="System.Double" returnType="Number" settingType="Coveo.Framework.Configuration.FieldConfiguration, Coveo.Framework" />
            <fieldType fieldTypeName="commerce single control" type="System.Single" returnType="Number" settingType="Coveo.Framework.Configuration.FieldConfiguration, Coveo.Framework" />
            ...
          </fieldTypes>
        </fieldMap>
      </defaultIndexConfiguration>
    </coveo>
  </sitecore>
</configuration>

If the fieldTypes configuration doesn't work, you will have to configure each field separately in the <fieldNames hint="raw:AddFieldByFieldName"> section like this instead:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <coveo>
      <defaultIndexConfiguration>
        <fieldMap>
          <fieldNames hint="raw:AddFieldByFieldName">
            <fieldType fieldName="adjustedprice" isFacet="true" isSortable="true" type="System.Double" returnType="Number" settingType="Coveo.Framework.Configuration.FieldConfiguration, Coveo.Framework" />
            <fieldType fieldName="customeraveragerating" isFacet="true" isSortable="true" type="System.Single" returnType="Number" settingType="Coveo.Framework.Configuration.FieldConfiguration, Coveo.Framework" />
            ...
          </fieldNames>
        </fieldMap>
      </defaultIndexConfiguration>
    </coveo>
  </sitecore>
</configuration>

After configuring the fields, I recommend you to delete your Coveo sources and field sets (if you are using the on-premises CES7 index platform) related to Sitecore before re-indexing because changing a field type in Coveo can be problematic if there are older indexed documents referencing the old field.

I know this is not a tested answer but I hope this helps you to configure the indexing.

Jeff

Gravatar for dean_thrasher@epam.com

Comment by Dean Thrasher, Jul 7, 2016 3:16 PM

Thanks for the advice, Jeff. We'll test it out and let you know what happens.

Gravatar for dean_thrasher@epam.com

Comment by Dean Thrasher, Jul 13, 2016 9:28 AM

Hi Jeff, after some further investigation, here's what we found:

The AddFieldByFieldTypeName isn't supported. We get the error message: "Could not find add method: AddFieldByFieldTypeName (type: Coveo.AbstractLayer.CoveoDefaultIndexConfiguration)"

Configuring each field in the section didn't help, either, they still were indexed as strings.

What does work is creating a computed field for these custom field types defined by the reference storefront, so we're using this as a workaround.

Gravatar for akshaysura@gmail.com

Comment by akshaysura, Sep 22, 2016 12:09 PM

<coveo>
  <defaultIndexConfiguration>
    <fieldMap type="Coveo.SearchProvider.CoveoFieldMap, Coveo.SearchProvider">
      <fieldNames hint="raw:AddFieldByFieldName">

add field by field name is under the field map.

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Sep 22, 2016 12:57 PM

You're right @akshaysura. I forgot the <fieldMap> node in my answer. I updated it. Thanks.

Ask a question