Copied to clipboard

Flag this post as spam?

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


  • JLon 321 posts 473 karma points
    Jan 14, 2017 @ 23:25
    JLon
    0

    Getting back Nested Content from ContentIndexingEvent

    Hi All,

    Within my IndexingEventsGathering, i've filtered the id key back and to pass it into the Umbraco helper like the one below.

    I've then tried to call to get the collection of Nested Content but it always returns null. Any idea how i can get Nested Content back this way?

    Thanks

    private void ContentIndexingEventsGatheringNodeData(object sender, IndexingNodeEventArgs e, UmbracoHelper helper)
        {
            if (e.IndexType != IndexTypes.Content) return;
    
            var fields = new Dictionary<string, string>(e.Fields);
    
            foreach (var field in fields)
            {
                // filtered down to a docType, then get the id
                var key = field.Key;
                 if (key == "id")
                 {
                    var node = helper.TypedContent(convertedId);
    
                    // nestedItems keep returning null here
                    var nestedItems = node.GetPropertyValue<IEnumerable<IPublishedContent>>("contentItems");
                 }
            }
        }
    
  • Ismail Mayat 4350 posts 9405 karma points MVP 2x admin c-trib
    Jan 16, 2017 @ 09:11
    Ismail Mayat
    0

    JLon,

    How are you getting the UmbracoHelper and passing it into the method? Is helper null? Or is node returned null?

    Regards

    Ismail

  • Lee Kelleher 3884 posts 14615 karma points MVP 9x admin c-trib
    Jan 16, 2017 @ 09:40
    Lee Kelleher
    0

    Similar question about the convertedId - not sure where that's coming from? (I assume you've snipped some of the code snippet for brevity?)

    I'm sure that the e.Fields would contain the value for the "contentItems" property - it'd be in JSON format, but it depends what you want to do with the data.

    Cheers,
    - Lee

  • JLon 321 posts 473 karma points
    Jan 16, 2017 @ 12:10
    JLon
    0

    Yup it comes back with the whole JSON, any extensions that I can use to convert it to IEnumerable

    Thanks Lee

  • Lee Kelleher 3884 posts 14615 karma points MVP 9x admin c-trib
    Jan 16, 2017 @ 12:22
    Lee Kelleher
    100

    Hey JLon,

    If you need an IEnumerable<IPublishedContent>, then it gets tricky as NestedContent needs to have the context of the node itself - it needs to know the property-type and associated doctype, etc.

    Depending on what data you need to get from the NestedContent items, you could deserialize it into an ad-hoc model?

    e.g. var ncItems = JsonConvert.DeserializeObject<List<object>>(...the JSON string...);

    Hope that makes sense?


    If you can explain more about what you are trying to do, it's possible that we may already have a potential solution for it.

    I'm assuming that you want to index the NC data into Examine?
    Check out this code snippet that Matt did: https://gist.github.com/mattbrailsford/7eb24abe61a4c896b3e5

    Cheers,
    - Lee

  • Stefano Beretta 79 posts 223 karma points
    Jul 12, 2019 @ 09:55
    Stefano Beretta
    0

    HIi Lee,

    is there a way to obtain a List<IPublishedContent> or a List<*MyModelsBuilderModel*> from the json of a nested content property?

    Thank you

    S

  • Lee Kelleher 3884 posts 14615 karma points MVP 9x admin c-trib
    Jul 15, 2019 @ 07:08
    Lee Kelleher
    0

    Hi Stefano, do you mean within the context of Examine indexing?

    If so, I'm not so sure it's the correct approach, as the JSON would need to be ran through each item's own property value-converters, (in order to strongly-type various values). My honest answer is that would be quite a lot of processing/overhead to get intellisense benefits - if that's what you are after?

    The optimum way to index is to understand the data you want to index into Examine and manipulate appropriately. It's all subjective to your requirements - which I guess doesn't really answer your question.

  • Stefano Beretta 79 posts 223 karma points
    Jul 15, 2019 @ 07:34
    Stefano Beretta
    0

    Hi Lee!

    No, nothing about indexing, sorry if I wasn't clear.

    My situation is the following:

    I'm using uConfiguration to store some structured information. One of the info stored is a NC.

    uConfiguration has its own property converters for contents and media picker (giving back an IPublishedContent), but it doesn't work when a property is a NC (I thought that maybe it would work since NC and uConfiguration can return both and IPublishedContent, but I was REAAAALLY wrong).

    The only not null result I can obtain is when I use ConfigurationHelper.Value<string>("my.alias"); that gives me back the NC json as a string.

    So I was trying to get an IPublishedContent from the json saved in the NC property (here's the json, a NC with a textbox, a content picker, three fluidity pickers and a doctype picker):

    [ { "key": "518a2b59-7bb4-42f9-8c15-df4633310026", "name": "Item 1", "ncContentTypeAlias": "creationLogic", "creationLabel": "Principal investigators", "node": "umb://document/12b053ac7bcb48a581764bd9332c2e71", "jobs": "2181,2182,2183,2172", "units": "1150,1154", "notOfUnits": "2250", "doctype": [ { "alias": "principalInvestigator", "name": "Principal Investigator" } ] } ]
    

    I was trying to avoid more coding considering that there's nothing really custom, but I think I'll have to make a custom uConfiguration property converter.

    Thank you very much!

    S

  • Lee Kelleher 3884 posts 14615 karma points MVP 9x admin c-trib
    Jul 15, 2019 @ 07:59
    Lee Kelleher
    0

    Hi Stefano, ah ok, think it was because this thread was specifically about indexing NC values into Examine.

    I don't know anything about the uConfiguration package, so not sure how it is trying to convert values, etc. Given what you've said, my assumption is that you'd need a custom converter too.

    I'm not sure which version of NC or Umbraco you are using, (my assumption is the NC package version, 0.5.0 and between Umbraco v7.6-10).

    In terms of code that may help you. Take a look at NC's value-converter...

    https://github.com/umco/umbraco-nested-content/blob/0.5.0/src/Our.Umbraco.NestedContent/Converters/NestedContentValueConverter.cs#L18

    Although the biggest gotcha there, is that you'd need to fake the PublishedPropertyType somehow? I'm not sure if uConfiguration offers anything similar to that?

    Good luck!

    Chees,
    - Lee

  • JLon 321 posts 473 karma points
    Jan 16, 2017 @ 12:24
    JLon
    0

    Cool. Guess I'll do it that way then. Thanks Lee

Please Sign in or register to post replies

Write your reply to:

Draft