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");
}
}
}
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.
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.
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.
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):
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.
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...
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?
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
JLon,
How are you getting the UmbracoHelper and passing it into the method? Is helper null? Or is node returned null?
Regards
Ismail
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
Yup it comes back with the whole JSON, any extensions that I can use to convert it to IEnumerable
Thanks Lee
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
HIi Lee,
is there a way to obtain a
List<IPublishedContent>
or aList<*MyModelsBuilderModel*>
from the json of a nested content property?Thank you
S
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.
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):
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
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
Cool. Guess I'll do it that way then. Thanks Lee
is working on a reply...