2

I am trying to create a commuted index field in sitecore 9 but can't get the configuration to work. I have a local environment which is running Solr and also environment is Azure.

I have added the following configuration to my indexing patch config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <contentSearch>
      <indexConfigurations>
        <defaultSolrIndexConfiguration>
          <fields hint="raw:AddComputedIndexField">
            <field fieldName="icon_services" returnType="string">Sitecore.Foundation.Indexing.Infrastructure.Fields.ImageURLComputedField, Sitecore.Foundation.Indexing</field>
          </fields>
        </defaultSolrIndexConfiguration>
      </indexConfigurations>
    </contentSearch>
  </sitecore>
</configuration>

This configuration throws the following error:

Server Error in '/' Application. Could not find add method: AddComputedIndexField (type: Sitecore.ContentSearch.SolrProvider.SolrIndexConfiguration)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Sitecore.Exceptions.RequiredObjectIsNullException: Could not find add method: AddComputedIndexField (type: Sitecore.ContentSearch.SolrProvider.SolrIndexConfiguration)

My code for computed index:

public class ImageURLComputedField : IComputedIndexField
  {
    public string FieldName { get; set; }
    public string ReturnType { get; set; }

    public object ComputeFieldValue(IIndexable indexable)
    {
      Assert.ArgumentNotNull(indexable, "indexable");
      string url = null;
      try
      {
        Item item = indexable as SitecoreIndexableItem;

        // This field only works for items uder /sitecore/content that have a layout
        if (item == null
            || item.Visualization.Layout == null
            || !item.Paths.FullPath.StartsWith(
                    Sitecore.Constants.ContentPath,
                    System.StringComparison.InvariantCultureIgnoreCase))
        {
          return null;
        }
        ImageField img = item.Fields["Icon"];

        return img == null || img.MediaItem == null ? null : MediaManager.GetMediaUrl(img.MediaItem);
      }
      catch (WebException webExc)
      {
        Log.Warn(string.Format("Failed to html index {0} ({1}): {2}", indexable.Id, url, webExc.Message), webExc, this);
      }
      catch (Exception exc)
      {
        Log.Error(string.Format("An error occurred when indexing {0}: {1}", indexable.Id, exc.Message), exc, this);
      }
      return null;
    }
  }

4 Answers 4

7

In Sitecore 8.2 there was one additional xml tag in the config, documentOptions. I don't have Sitecore 9 instance running at the moment, but I expect it's the same:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <contentSearch>
      <indexConfigurations>
        <defaultSolrIndexConfiguration>
          <documentOptions> <!-- MISSING -->
            <fields hint="raw:AddComputedIndexField">
              <field fieldName="icon_services" returnType="string">Sitecore.Foundation.Indexing.Infrastructure.Fields.ImageURLComputedField, Sitecore.Foundation.Indexing</field>
            </fields>
          </documentOptions> <!-- MISSING -->
        </defaultSolrIndexConfiguration>
      </indexConfigurations>
    </contentSearch>
  </sitecore>
</configuration>
1
0

I needed to add the following configuration to make custom field shown in the solr Index.I am trying to add it to a custom index(not default indexes).Adding FieldMap tag will map the field and index it.

 <documentOptions type="Sitecore.ContentSearch.SolrProvider.SolrDocumentBuilderOptions, Sitecore.ContentSearch.SolrProvider">
            <include hint="list:AddIncludedTemplate">
              <CustomDetails>{B713DC5E-1A10-40D5-A9C0-3DFF1431D05B}</CustomDetails>
            </include>
            <fields hint="raw:AddComputedIndexField">
              <field fieldName="FacetCategory" returnType="string">Foundation.Location.Repository.FacetsComputedField, Foundation.Location</field>
            </fields>
          </documentOptions>
         <fieldMap ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration/fieldMap">
           <fieldNames hint="raw:AddFieldByFieldName">
                        <fieldType fieldName="FacetCategory" returnType="string" />
          </fieldNames>
        </fieldMap>
0

Google lands me on this page, however, I had a different error:

HttpException (0x80004005): Could not find add method: AddPrefetch (type: System.String)

After a long investigation I figured that if some other library is referenced by Sitecore related DLLs, you may get some weird errors, anyway I figured that Unicorn related DLLs (Rainbow .*.dll, Unicorn.dll), were missing, as I only copied the project DLL to the Bin, while the config files related to Unicorn were still there under App_config. Hope it helps. Either delete unnecessary config files or make sure any module/package there in config files has the relevant DLLs in the bin folder.

-1

I added the following patch file for Azure search to work

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <contentSearch>
      <indexConfigurations>
        <defaultCloudIndexConfiguration>
          <documentOptions>
            <fields hint="raw:AddComputedIndexField">
              <field fieldName="icon_services" returnType="string">Sitecore.Foundation.Indexing.Infrastructure.Fields.ImageURLComputedField, Sitecore.Foundation.Indexing</field>
            </fields>
          </documentOptions>
        </defaultCloudIndexConfiguration>
      </indexConfigurations>
    </contentSearch>
  </sitecore>
</configuration>
1
  • 3
    Arun, your answer looks exactly the same as the accepted answer. Is there any reason you decided to post it as a separate answer? Commented Feb 12, 2018 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.