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>