Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Lets try again! Does anyone have an example of how I could go about creating an Examine query to get....
All Child pages
Where property value Category contains Querystring parameter, or any the Categories property parents contain the same Query String parameter?
-- I was trying to do this using LINQ, which only got me the property and the properties parent property, I need at least 3 levels. e.g Home > Article page > Return Property value of category in article page > if it's got a parent category bring that back too > if that's got a parent bring that back too etc etc.
-- Original Post below probably not that relevant now--
I'm trying to pull back all the pages on my site that have a specific ID set in the package Utaxonomy and whilst I can get pages that have a tag easily, bringin back pages that contain parent tags is proving more challenging.
In the below, QS is the GUID set within uTaxonomy.
var AllPagesWithTags = Model.Content.Children.Where(x => x.IsVisible() && (x.GetPropertyValue<List<Taxonomy>>("category")
.Select(y => y.Id.ToString()).ToList().Contains(qsCategory)
.Select(y => y.Parent != null ? y.Parent.Id.ToString() : null).ToList().Contains(qsCategory))
Is there a way to write the above so it checks the parent, parents parent, parents parents parent etc, recursively so I can increase the number of taxonomy levels without having to amend the code?
I'm not sure about the package, but you could do:
Which will search all children and children of children etc.
There is obviously a performance hit to doing this though, especially on a large site.
I would recommend avoiding using of Descendants(), read more - https://our.umbraco.com/documentation/Reference/Common-Pitfalls/#querying-with-descendants-descendantsorself
The best way is to use XPath or examine indexes for such complex search.
Ok thanks guys.
Yeah I wasn't going to use descendants, I only want to look at one level of child pages. So...
Home > Article page > Property value of category in article page > if it's got a parent category bring that back > if that's got a parent bring that back etc etc.
I thought Examine might be an option but was hoping to avoid it given I've very little experience with it.
If I understand it correctly you would like to get all the nodes where the parent category property is set to the querystring provided value.
If so, my approach would be the following:
Search with Examine for the nodes that contains the category value. Then instantiate the found pages with the Umbraco helper to get a list of IPublishedContent objects. Then you're able to retrieve the children of this pages.
When you don't like it to use the Umbraco helper, I would add the parent category value to all child nodes in the Examine index using the OnGatheringNodeData event. When you are publishing a node that contains a category value you should publish all child nodes as well. Then in the OnGatheringNodeData event you can add custom fields to the Examine index.
With this approach you can simple search for the category value on all nodes.
Something like this:
var helper = new UmbracoHelper(UmbracoContext.Current);
var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
var query = searcher
var results = searcher.Search(query);
IEnumerable<IPublishedContent> pages = results.SelectMany(x => helper.TypedContent(x.Id).Children);
Thank you, this looks great. Many thanks for taking the time to reply. :-)
Sorted with Examine. Thanks all.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted