I have a document type Article that has a tag property and I'm trying to create a function that will return all articles that have a specific tag. The solution that I have come up with so far is this:
However this function is not specific enough and will return articles where the tag appears anywhere in an articles tag collection and not where an article has a specific tag i.e if I search for articles tagged 'cat' it would return articles tagged 'catamaran' or 'catapault' etc as well as those tagged 'cat'. To make it more specific I changed the query to:
var test = Umbraco.AssignedContentItem.Descendants().ToList().Where(x => x.GetPropertyValue("tags") != null && x.GetPropertyValue<string>("tags").Contains("tagValue"));
Cheers for the input, unfortunately that has the same results as my first query, though I can modify it so that it does work. Unfortunately its not going to be very efficient as its going to retrieve all descendants before filtering them rather than the iqueryable that is returned by my initial method which also allows me to page the results.
Getting document nodes by tag
I have a document type Article that has a tag property and I'm trying to create a function that will return all articles that have a specific tag. The solution that I have come up with so far is this:
CurrentPage.Descendants("ArticlePage").Where(" string.IsNullOrEmpty(@0) || Tags.Contains(@0)", tag)
However this function is not specific enough and will return articles where the tag appears anywhere in an articles tag collection and not where an article has a specific tag i.e if I search for articles tagged 'cat' it would return articles tagged 'catamaran' or 'catapault' etc as well as those tagged 'cat'. To make it more specific I changed the query to:
CurrentPage.Descendants("ArticlePage").Where(" string.IsNullOrEmpty(@0) || (Tags != null && Tags.Split(',').Any(t => t.Trim() == @0))", tag)
However this gives me the error:
No applicable method 'Split' exists in type 'String'
Any ideas on how to get this working?
Anybody got any ideas?
Hi Patrick,
You can try like that :
Thanks, Alex
Cheers for the input, unfortunately that has the same results as my first query, though I can modify it so that it does work. Unfortunately its not going to be very efficient as its going to retrieve all descendants before filtering them rather than the iqueryable that is returned by my initial method which also allows me to page the results.
is working on a reply...