Gravatar for sheerahinkey@ccimail.com

Question by sheerahinkey, Mar 11, 2015 11:43 AM

computed field not being indexed

I have a computed field where i am trying to store date from an ancestor item on the item, for some reason this field does not get indexed on the items.

config file:

<fieldNames hint="raw:AddFieldByFieldName">
  <field fieldName="quarterly_issue" isFacet="true" boost="1f" type="System.GUID" settingType="Coveo.Framework.Configuration.FieldConfiguration, Coveo.Framework" />
</fieldNames>
<fields hint="raw:AddComputedIndexField">
  <field fieldName="quarterly_issue">Plough._Classes.Plough.ContentSearch.ComputedFields.QuarterlyIssue, Plough</field>
</fields>

This is my logic to compute the field:

namespace Plough._Classes.Plough.ContentSearch.ComputedFields
{
    public class QuarterlyIssue
    {
        public string FieldName { get; set; }

        public string ReturnType { get; set; }

        public object ComputeFieldValue(Sitecore.ContentSearch.IIndexable indexable)
        {
            Assert.ArgumentNotNull(indexable, "indexable");
            var scIndexable = indexable as SitecoreIndexableItem;

            if (scIndexable == null)
            {
                Log.Warn(this + " : unsupported IIndexable type : " + indexable.GetType(), this);
                return null;
            }

            var item = (Item)scIndexable;

            if (item == null)
            {
                Log.Warn(this + " : unsupported SitecoreIndexableItem type : " + scIndexable.GetType(), this);
                return null;
            }

            // optimization to reduce indexing time
            // by skipping this logic for items in the Core database
            if (System.String.Compare(item.Database.Name, "core", System.StringComparison.OrdinalIgnoreCase) == 0)
                return null;

            if (item.Paths.IsMediaItem)
                return null;

            if (item.TemplateID.ToString() == Constants.TemplateGUID_Review || item.TemplateID.ToString() == Constants.TemplateGUID_Acclaim)
            {
                var product = item.Parent.Parent;
                if (product != null && product.Fields[Constants.FieldName_Quarterly_Issue] != null)
                {
                    var issueField = (Sitecore.Data.Fields.ReferenceField)product.Fields[Constants.FieldName_Quarterly_Issue];
                    if (issueField != null)
                        return IdHelper.ProcessGUIDs(issueField.TargetID.ToString());
                }
            }

            if (item.Fields[Constants.FieldName_Quarterly_Issue] != null && item.Fields[Constants.FieldName_Quarterly_Issue].HasValue)
            {
                var issueField = (Sitecore.Data.Fields.ReferenceField)item.Fields[Constants.FieldName_Quarterly_Issue];
                if (issueField != null)
                     return IdHelper.ProcessGUIDs(issueField.TargetID.ToString());
            }

            return null;
        }
    }
}
Gravatar for slangevin@coveo.com

Comment by Simon, Mar 11, 2015 11:57 AM

Have you tried a rebuild of the item using the Developer tab in the Content Editor?

1 Reply
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Mar 11, 2015 11:58 AM

  1. The name of the XML elements in the <fieldNames hint="raw:AddFieldByFieldName"> element should be fieldType instead of field.
  2. I don't see any return statement that returns anything other than null in your code. I think you miss some in the last 2 if statements.
  3. You told that you try to compute a date from an ancestor item but your code and config shows that you're likely computing a GUID.
Gravatar for sheerahinkey@ccimail.com

Comment by sheerahinkey, Mar 11, 2015 2:06 PM

Sorry, I forgot to add the return statements. I edited my question, but that wasn't the issue.

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Mar 11, 2015 3:22 PM

What about points #1 and #3?

Ask a question