Copied to clipboard

Flag this post as spam?

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


  • Alastair Todd 44 posts 142 karma points
    Jul 09, 2016 @ 08:27
    Alastair Todd
    0

    Properties empty/erroring in GatheringNodeData

    I saw a couple of posts that said in overriding Indexing via GatheringNodeData it was inefficient to use:

    var content = ApplicationContext.Current.Services.ContentService.GetById(e.NodeId);
    

    but when I use

    var content = umbraco.TypedContent(e.NodeId);
    

    Many of the properties are erroring as object not set.

    I've reverted to :

     var content = new Node(e.NodeId);
    

    But that feels regressive.

    Thoughts?

  • Marc Goodson 2157 posts 14431 karma points MVP 9x c-trib
    Jul 10, 2016 @ 11:48
    Marc Goodson
    1

    Hi Alastair

    I guess it depends on what you are trying to do ?

    The content service can perform slowly if you are using it to pull back large amounts of data, as it accesses the database directly.

    The Umbraco helpers read from the Umbraco Cache file, but you need an Umbraco Context to be able to use them, and examine is probably running async, outside of the webrequest. UmbracoContect.Current will be null. The workaround is to 'ensure' a httpcontext:

       if (UmbracoContext.Current == null)
                    {
                        var dummyHttpContext =
                            new HttpContextWrapper(
                                new HttpContext(new SimpleWorkerRequest("blah.aspx", "", new StringWriter())));
                        UmbracoContext.EnsureContext(
                            dummyHttpContext,
                            ApplicationContext.Current,
                            new WebSecurity(dummyHttpContext, ApplicationContext.Current),
                            UmbracoConfig.For.UmbracoSettings(),
                            UrlProviderResolver.Current.Providers,
                            false);
                    }
                  UmbracoHelper umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
    

    But also you can access the fields of the item being indexed via the gathering nodes Event Args eg:

      if (e.Fields.ContainsKey("myPropertyName")){
    var myPropertyNameVariable = e.Fields["myPropertyName"];
    }
    

    and then there is no additional lookup involved.

    So it depends on what you are trying to do.

  • Alastair Todd 44 posts 142 karma points
    Jul 10, 2016 @ 11:55
    Alastair Todd
    0

    Thanks for the HttpContext heads-up will give it a go.

    This was my problem, I would use e.Fields, but there's an RTE field in there that has been stripped of it's html.

    The whole point of using Examine here is for performance reasons - I don't at front-end run-time want to have to go back into the content cache to retrieve certain fields (html). (a lot of content, its a factor of 10 times slower than Lucene in my scenario).

    So the idea was to include the unstripped html in the index. So i need to get at the raw property value.

    var content = new Node(e.NodeId); seems to work just fine and for now there's no obsolete attribute on it, so...

Please Sign in or register to post replies

Write your reply to:

Draft