I have a custom computedfield in Sitecore 9.1.1.
I am getting the below error on CD server only as my web.config has:
<add key="role:define" value="ContentDelivery" />
Current CustomIndex config:
<contentSearch>
<indexConfigurations>
<extendedSolrIndexConfiguration type="Sitecore.ContentSearch.SolrProvider.SolrIndexConfiguration, Sitecore.ContentSearch.SolrProvider">
<documentOptions type="Sitecore.ContentSearch.SolrProvider.SolrDocumentBuilderOptions, Sitecore.ContentSearch.SolrProvider" >
<fields hint="raw:AddComputedIndexField">
<field fieldName="helpdesk_content" storageType="NO" indexType="TOKENIZED">Sitecore.Feature.Helpdesk.Infrastructure.Fields.HelpDeskContentComputedField, Sitecore.Feature.Helpdesk</field>
</fields>
</documentOptions>
</extendedSolrIndexConfiguration>
</indexConfigurations>
</contentSearch>
Custom Index code:
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;
}
// Determine the url to request
using (new DatabaseSwitcher(item.Database))
{
//explicitly resolve context site
var site = item.GetContextSite();
url = WebUtil.AddQueryString(
LinkManager.GetItemUrl(item, new UrlOptions()
{
AlwaysIncludeServerUrl = true,
Site=site
}),
"sc_database", Sitecore.Context.Database.Name);
}
// Http request the page
using (var client = new WebClient())
{
Log.Debug(string.Format("Indexing content for the URL [{0}]", url));
string pageContent = client.DownloadString(url);
// Parse the page's html using HtmlAgilityPack
HtmlDocument htmlDocument = new HtmlDocument();
htmlDocument.LoadHtml(pageContent);
// Strip out all the html tags, so we can index just the text
HtmlNode mainContainer = htmlDocument.DocumentNode.Descendants("body").FirstOrDefault();
string content = mainContainer != null ? GetAllInnerTexts(mainContainer) : null;
Log.Debug("content indexed : " + content);
return content;
}
}
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;
}
Error on CD server:
ERROR An error occurred when indexing {0CAA7DB1-CAF8-48EA-8BD0-DA191B4BCF46}: Could not find configuration node: databases/database[@id='core']
Exception: System.InvalidOperationException
Message: Could not find configuration node: databases/database[@id='core']
Source: Sitecore.Kernel
at Sitecore.Configuration.DefaultFactory.GetConfigNode(String xpath, Boolean assert)
at Sitecore.Configuration.DefaultFactory.CreateObject(String configPath, String[] parameters, Boolean assert)
at Sitecore.Configuration.DefaultFactory.GetDatabase(String name, Boolean assert)
at Sitecore.Configuration.DefaultFactory.GetDatabase(String name)
at Sitecore.Sites.SiteContext.get_Database()
at Sitecore.Foundation.Indexing.Infrastructure.Fields.HtmlCrawledField.ComputeFieldValue(IIndexable indexable) in C:\Projects\Unitywater\src\foundation\Indexing\code\Infrastructure\Fields\HtmlCrawledField.cs:line 51
Do I need to disable the custom indexing on the CD server on have to make it based on specific database? What sort of configuration you normally have in CD server for custom index?