Examine - Index children and picked nodes as part of parent
I have children and picked nodes that render as part of a parent page.
Is there a way to extend the ExternalIndexer so picked or child nodes are indexed into the same record as the parent?
use gathering node data event and for the current item get its children and any picked nodes then get them and inject their content into the fields property for the current item being indexed.
Thanks for the pointer Ismail,
We have a lot of Factories to create viewModels, I'd like to re-use these to generate indexable content... however they all rely on Umbraco.Context, which is not present when indexing.
The most common issue is any call to GetPropertyValue<string>(...) will fail when it hits Umbraco.Web.Templates.TemplateUtilities.ParseInternalLinks
But I'm guessing macros will fail also.
Is there a way around this?
Create a fake UmbracoContext?
currently, my factory has ugly if statements like this:
ExpandCollapse viewModel;
if (UmbracoContext.Current == null)
{
viewModel = new ExpandCollapse
{
Heading = nestedContent.GetProperty("heading")?.DataValue.ToString(),
// snip //
};
}
else
{
viewModel = nestedContent.Map<T>(); // using https://github.com/AndyButland/UmbracoMapper
}
Simplified Example:
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
var helper = new UmbracoHelper(UmbracoContext.Current);
ExamineManager.Instance.IndexProviderCollection["ExternalIndexer"].GatheringNodeData
+= (sender, e) => Indexer_GatheringNodeData(sender, e, helper);
}
void ExamineEvents_GatheringNodeData(object sender, IndexingNodeDataEventArgs e, UmbracoHelper helper)
{
//check if this is 'Content' (as opposed to media, etc...)
if (e.IndexType == IndexTypes.Content)
{
var page = helper.TypedContent(e.NodeId);
var title = page.GetPropertyValue<string>("title");
// NullReferenceException in "Umbraco.Web.Templates.TemplateUtilities.ParseInternalLinks"
Examine - Index children and picked nodes as part of parent
I have children and picked nodes that render as part of a parent page. Is there a way to extend the ExternalIndexer so picked or child nodes are indexed into the same record as the parent?
use gathering node data event and for the current item get its children and any picked nodes then get them and inject their content into the fields property for the current item being indexed.
Thanks for the pointer Ismail,
We have a lot of Factories to create viewModels, I'd like to re-use these to generate indexable content... however they all rely on Umbraco.Context, which is not present when indexing. The most common issue is any call to
GetPropertyValue<string>(...)
will fail when it hitsUmbraco.Web.Templates.TemplateUtilities.ParseInternalLinks
But I'm guessing macros will fail also.Is there a way around this?
Create a fake UmbracoContext? currently, my factory has ugly if statements like this:
Simplified Example:
is working on a reply...