In our previous Sitecore application, we sometimes need to have a custom computed index field based on the business requirements.  For example, we might need an extra field for faceting purpose of certain data template. In order to have a custom index field, you need to create a custom class that inherits from the AbstractComputedIndexField.

The class and function should look like the following:

public class CustomField : AbstractComputedIndexField
        public override object ComputeFieldValue(IIndexable indexable)
            object ret = null;
            //Code to generate the field content and assign to the return object.
            return ret;

In your custom config file, make sure you have the following section pointing to your custom class and namespace:

<fields hint="raw:AddComputedIndexField">
	<field fieldName="customFieldName">CAGovPortal.Custom.Index.ComputedFields.CustomField, CAGovPortal</field>

If you need to have full string of content in the field instead of individual word index, you need to have the following configurations for the field data to be tokenized.

<fieldMap type="Sitecore.ContentSearch.FieldMap, Sitecore.ContentSearch">
      <fieldNames hint="raw:AddFieldByFieldName">
              <field fieldName="customFieldName" storageType="YES" indexType="TOKENIZED" vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
                <analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.LowerCaseKeywordAnalyzer, Sitecore.ContentSearch.LuceneProvider" />

The custom code should run on the item save event to save the index.  You can use the Index manager to rebuild the index to see the result as well.