Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Murray Roke 503 posts 966 karma points c-trib
    Jun 20, 2019 @ 00:57
    Murray Roke
    0

    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?

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Jun 20, 2019 @ 08:15
    Ismail Mayat
    100

    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.

  • Murray Roke 503 posts 966 karma points c-trib
    Jun 26, 2019 @ 00:08
    Murray Roke
    0

    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"
    
Please Sign in or register to post replies

Write your reply to:

Draft