0

I am trying to add links and extending the implementation of the GetLayoutReferences method from Sitecore.XA.Foundation.Search.ComputedFields.AggregatedContent class. However I am getting the following error:

Could not find the computed index field type: 
BXS.XA.Foundation.Custom.Search.AggregatedContent, BXS.XA.Foundation.Custom.Search 

Here is my class code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sitecore.Data.Fields;
using Sitecore.Data.Items;
using Sitecore.Layouts;
using Sitecore.Text;

namespace BXS.XA.Foundation.Custom.Search
{
    public class AggregatedContent : Sitecore.XA.Foundation.Search.ComputedFields.AggregatedContent
    {
        protected override IEnumerable<Item> GetLayoutReferences(Item item, ISet<Item> dataFolders)
        {
            LayoutField layoutField = new LayoutField(item);
            using (new ContextItemSwitcher(item))
            {
                DeviceItem[] all = item.Database.Resources.Devices.GetAll();
                foreach (DeviceItem device in all)
                {
                    IEnumerable<RenderingReference> references = layoutField.GetReferences(device);
                    foreach (RenderingReference item3 in references ?? Enumerable.Empty<RenderingReference>())
                    {
                        string[] items = new ListString(item3.Settings.DataSource ?? string.Empty).Items;
                        foreach (string path in items)
                        {
                            Item item2 = item.Database.GetItem(path, item.Language, Sitecore.Data.Version.Latest);
                            if (item2 != null && IsDataItem(item2, dataFolders))
                            {
                                // custom - start
                                if (item2.TemplateName == "Link List")
                                {
                                    foreach (Item linkItem in item2.Children)
                                    {
                                        var field = (LinkField)linkItem.Fields["Link"];
                                        if (field.IsInternal)
                                        {
                                            yield return field.TargetItem;
                                        }
                                    }
                                }
                                // custom - end
                                yield return item2;
                            }
                        }
                    }
                }
            }
        }
    }
}

And here is my config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:search="http://www.sitecore.net/xmlconfig/search/">
  <sitecore>
    <contentSearch search:require="solr">
      <indexConfigurations>
        <defaultSolrIndexConfiguration>
          <documentOptions>
            <fields hint="raw:AddComputedIndexField">
              <field fieldName="sxacontent">
                <patch:delete />
              </field>
              <field fieldName="sxacontent" returnType="textCollection" type="BXS.XA.Foundation.Custom.Search.AggregatedContent, BXS.XA.Foundation.Custom.Search">
                <mediaIndexing ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration/mediaIndexing"/>
              </field>
            </fields>
          </documentOptions>
        </defaultSolrIndexConfiguration>
      </indexConfigurations>
    </contentSearch>
  </sitecore>
</configuration>
6
  • 3
    What you will need to try is change your project namespace to something different so it does not collide with SXA names. You could try Olivia.XA.Foundation and then update the patch to match the new namespace and library. – Michael West Mar 18 at 3:12
  • 1
    you have to register the assembly like this your method for computed field, your dll Sitecore.XA.Foundation.Custom.Search.AggregatedContent, Sitecore.XA.Foundation.Custom – Amro Mustafa Mar 18 at 13:23
  • @MichaelWest I just changed it and am still receiving the same error. I updated my code above. – Olivia Shettles Mar 18 at 13:38
  • 1
    "BXS.XA.Foundation.Custom.Search" - Is it the name of your DLL? If not change the part after "," to name of your DLL "BXS.XA.Foundation.Custom.Search.AggregatedContent, BXS.XA.Foundation.Custom.Search" @OliviaShettles – Vadim Birkos Mar 18 at 13:47
  • @VadimBirkos that was it. Thank you! – Olivia Shettles Mar 18 at 14:22
1

I can assume that the Assemble Name part in

"BXS.XA.Foundation.Custom.Search.AggregatedContent, BXS.XA.Foundation.Custom.Search" 

does not exist in your solution.

Please, check that your Assemble Name is correct. It has to have next format:

{ClassNamespace}.{ClassName}, {AssembleName}

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