Copied to clipboard

Flag this post as spam?

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


  • Patrick Robin 34 posts 104 karma points
    Apr 09, 2015 @ 11:52
    Patrick Robin
    0

    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?

  • Patrick Robin 34 posts 104 karma points
    Apr 21, 2015 @ 12:10
    Patrick Robin
    0

    Anybody got any ideas?

  • Alex Skrypnyk 6054 posts 23213 karma points MVP 5x admin c-trib
    Apr 21, 2015 @ 17:34
    Alex Skrypnyk
    0

    Hi Patrick,

    You can try like that :

    var test = Umbraco.AssignedContentItem.Descendants().ToList().Where(x => x.GetPropertyValue("tags") != null && x.GetPropertyValue<string>("tags").Contains("tagValue"));
    

    Thanks, Alex

  • Patrick Robin 34 posts 104 karma points
    Apr 21, 2015 @ 18:59
    Patrick Robin
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft