Gravatar for

Question by timothevs, Aug 19, 2015 12:23 PM

Postconversion script for a database source to update sys fields?

I am trying to follow the example set out in

I couldn't create a custom field called "Author" in the field set as I got the error "This name is already used." I assumed that "sysauthor" is using this as an alias.

So I tried to create a post conversion script to set this sysauthor field to John Adams. Here's what I have

using System;
using System.Linq;
using Coveo.CES.Interops.COMCoveoConvertersWrappers;

namespace Tutorial
    public class TestDBPostconversion : Coveo.CES.DotNetConverterLoader.CustomConverter
        public override void RunPostConverter(PostConversion p_PostConversion, DocumentInfo p_DocumentInfo)
            string author = null;
            if (p_DocumentInfo.Fields().Cast<String>().Any(w => w == "sysauthor"))
                author = p_DocumentInfo.GetFieldValue("sysauthor") as String;
            if (String.IsNullOrEmpty(author))
                author = "John Adams";
            p_DocumentInfo.SetFieldValue("sysauthor", author);

But it doesn't work. I tried to change it first by alias - author, and also tried to change another field - syssite. To no avail. Are these fields not available for post conversion scripts?

Gravatar for

Comment by Jean-François L'Heureux, Aug 19, 2015 3:48 PM

The SetFieldValue method can be confusing because it doesn't set a CES field value but it sets a metadata value. Its signature should be SetFieldValue(string p_MetadataName, string p_MetadataValue).

In the Coveo for Sitecore example you linked, the metadata name that is used is "author".

So, in CES, the following fields would be set to the value of the postconversion script:

  • Field Name: "author", Metadata Name: ""
  • Field Name: "author", Metadata Name: "author"
  • Field Name: "MyCustomFieldName", Metadata Name: "author"
Gravatar for

Comment by timothevs, Aug 19, 2015 4:24 PM

Interesting, I tried pDocumentInfo.SetFieldValue("author", author); as above, but it didn't work. In the meantime I did get it to work with pDocumentInfo.Author = author and that worked to change the sysauthor field, as per your suggestion.

However, for sitecore, the actual author name (used in the facet) is from the field name parsedcreatedby. I see it is an alias of fparsedcreatedby35863. When i try to set parsedcreatedby to John Adams with the post conversion script, it works fine for my external source, but then the facet doesn't show John Adams as an option.

Am I making any sense?

Gravatar for

Comment by Jean-François L'Heureux, Aug 19, 2015 5:17 PM

Did you set your postconversion script on all your sources (external source and all your Sitecore sources (web and master at least))? Also, did you rebuild your Sitecore indexes from the Sitecore Indexing Manager after setting the postconversion script on the sources? Rebuilding the indexes is mandatory when you want to change a field content like this.

Then, the facet should show your new author in its values.

Gravatar for

Comment by timothevs, Aug 20, 2015 8:20 AM

Admittedly, no, I only linked the post conversion script for the external Database source. My reasoning was that the fparsedcreatedby35863 for which parsedcreatedby is an alias in the Sitecore sources is already present in the index.

Values for fparsed… from sitecore get shown in the facet. Values for parsedcreatedby from DB source don't show up alongside. I reindexed the master, and web indices from Sitecore, but no go.

Then I tried to edit the Coveo.Searchprofile and added a fieldType for parsedcreatedby and now only the values from the db source show up in the facet. Confused.

2 Replies
Gravatar for

Answer by Jean-François L'Heureux, Aug 20, 2015 1:17 PM

I think we need to clarify some things.

The Sitecore "Author" facet uses the "parsedcreatedby" field (as we can see in /sitecore/system/Settings/Buckets/Facets/Author).

The "parsedcreatedby" field is a Sitecore computed field defined in the Coveo.SearchProvider.config file in the <fields hint="raw:AddComputedIndexField"> section.

The CES documents contains the @fparsedcreatedby35863 field or the @fparsedcreatedbyXXXXX field depending on their CES source. The hash number at the end differs between the sources (web/master) due to field translation to avoid field conflicts between sources.

Note: The "metadata name" property of CES fields is not an "alias" as you described. It is just the name of the metadata to use when indexing the field values. If you have a "@MyCustomField" field with a "MyMetadataName" metadata name, you can't query for @MyMetadataName==Something.

Your external database CES source should use a separate CES field set. It should't use your master or web sources field sets.

As we saw, the "parsedcreatedby" field can have 2 different names in CES. We don't want to create 2 "parsedcreatedby" fields in the external source field set. Thus, we will use the "external field" feature of Coveo for Sitecore to avoid the "parsedcreatedby" field translation.

In your Coveo.SearchProvider.config file, add a fieldType node in the <fieldNames hint="raw:AddFieldByFieldName"> section like this:

<fieldType fieldName="parsedcreatedby" isFacet="true" isExternal="true" settingType="Coveo.Framework.Configuration.FieldConfiguration, Coveo.Framework" />

This configuration tells Coveo for Sitecore that the "parsedcreatedby" field should be considered as an external field that should not be translated to "@fparsedcreatedbyXXXXX" but treated as "@parsedcreatedby". It also tells Coveo for Sitecore to set the field as a facet field in the CES fields sets.

After saving the file, you need to rebuild your Sitecore indexes for Coveo for Sitecore to delete the old "@fparsedcreatedbyXXXXX" and create the new "@parsedcreatedby" fields and set it in the re-indexed documents.

In your separate field set for your external source, create a "parsedcreatedby" field without a metadata name and set this field as facet too.

Then, in your external source postconversion script, you need to set the value of the "parsedcreatedby" metadata like this:

p_DocumentInfo.SetFieldValue("parsedcreatedby", author);

I hope this helps.


Gravatar for

Comment by timothevs, Aug 25, 2015 1:30 PM

Jeff, thank you for the most insightful and in-depth answer. That indeed cleared a lot of concepts up for me. I have successfully managed to make this work.

Gravatar for

Answer by Jean-François L'Heureux, Aug 19, 2015 2:04 PM

To alter the @sysauthor CES field value, you need to assign the p_DocumentInfo.Author property as the API describes:

The reason is that the @sysauthor field is just a queryable field over the Author property of a CES document.

Ask a question