Copied to clipboard

Flag this post as spam?

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


  • Kev 16 posts 67 karma points
    Jan 13, 2015 @ 13:39
    Kev
    0

    Get content by multiple tags not returning any results

    Hi all,

    I'm trying to get content by multiple tags using Umbraco.TagQuery.

    If I pass in the 1 tag as below, it returns a result set.

    Umbraco.TagQuery.GetContentByTag("Test")
    

    But if I try to search by a comma seperated string it returns nothing:

    Umbraco.TagQuery.GetContentByTag("Test,Test 2")
    

    Also, if I use the old method, everything works as intended:

    umbraco.cms.businesslogic.Tags.Tag.GetNodesWithTags("Test,Test 2").ToList().
    

    Am I doing something wrong here? Is this the best way to get content by tags?

    Thanks in advance,

    Kev

  • Valerie 67 posts 163 karma points
    Jan 13, 2015 @ 14:10
    Valerie
    0

    It looks like GetContentByTag only takes one tag unfortunately so it will be looking for one tag called "Test,Test 2" and failing.

    I've been using Examine to search by tags - if you add the tag property to your settings to make sure it is indexed then you can just run a search on that field.

  • Valerie 67 posts 163 karma points
    Jan 13, 2015 @ 14:11
    Valerie
    0

    Otherwise I guess you could run your old query and then inflate the IPublishedContent from the ids? Not ideal but I guess it's okay if you don't have a lot of content.

  • Kev 16 posts 67 karma points
    Jan 13, 2015 @ 15:35
    Kev
    0

    Aha. Using Examine sounds like a really good idea actually.

    Would you be able to show me an example by any chance?

    Thanks Valerie

  • Valerie 67 posts 163 karma points
    Jan 13, 2015 @ 16:27
    Valerie
    0

    HI,

    So normally I do a wee Examine event to replace any commas with spaces and lowercase the tag name and use this field to search on (so there's no need to add the field to examineIndex in this case). I've included an example of a simple search class.

    https://gist.github.com/anonymous/9955a1ee2b4cdef76cc0

    Valerie

     

  • Kev 16 posts 67 karma points
    Jan 13, 2015 @ 18:54
    Kev
    0

    Brilliant, thanks Valerie. I'll see if I can implement something along those lines :)

Please Sign in or register to post replies

Write your reply to:

Draft