More in this section

Forums / Developing with Sitefinity / Filtering a content list by multiple tags

Filtering a content list by multiple tags

3 posts, 0 answered
  1. LouiseBA
    LouiseBA avatar
    61 posts
    Registered:
    23 Mar 2010
    22 Apr 2010
    Link to this post
    Hi there!

    1. I'm creating a custom control to show news items (we call them Articles!). I need to filter the list in my custom control (essentially a repeater showing news items) by Category AND multiple tags. I have read that filtering by multiple tags is coming in 4.0, but we need it now :o/

    I have successfully got a list of news items back to match the category entered in a public property, and 1 tag.

     NewsManager newsManager = new NewsManager("News");
                   
            //Get list of news items with the stated category and content area (menu area)
            List<IMetaSearchInfo> filter = new List<IMetaSearchInfo>();
            filter.Add(new MetaSearchInfo(MetaValueTypes.ShortText, "Category", _category, SearchCondition.Equal, JoinType.And));
            IList newsList = newsManager.Content.GetContent(0, _maxArticles, "Publication_Date DESC", _contentArea, null, string.Empty, null, filter.ToArray());

    (where _category and _contentarea are public properties on my control - therefore editable on the edit page of the control. _contentarea is just another tag nothing special but just makes it more intuitive on the interface). I have another public property of 'tags' where we will type a list of comma seperated tags then I get them in my code behind using string.split )
           
    i now need to filter the list further by 1 or many more tags. I really dont want to loop through my tags and for each extra tags filter the list further. Very inefficient since it will do a round trip every time. Either way I dont know how to filter an already filtered list (i.e. filter my IList, newsList)

    Or can I just use SQL to access my content? since I can just write a sql query to get the items I want. I know it is bypassing sitefinity logic, but im scratching my head a little bit where normally i'd have written a sql statement to get content items by multiple tags, and done this task in half an hour.

    2. This is a less urgent question: but can I rename EVERY occurrence of 'news' to 'articles' in the system. We have articles, and news are types of articles, and the sitefinity dashboard will most definately confuse our users!! :o/

    Any help or ideas greatly appreciated.

    Thanks, Becky.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    23 Apr 2010
    Link to this post
    Hello LouiseBA,

    You could use intersection to filter the items by two tags

    string Tag1 = "MyTag1";  
    string Tag2 = "MyTag2";  
        
    var newsManager = new NewsManager("News");  
    IList listOfAllItems = newsManager.Content.GetContent(0, 0, string.Empty, Tag1);
    IList listOfAllItems1 = newsManager.Content.GetContent(0, 0, string.Empty, Tag2);
    // here we are using intersection
    List<IContent> intersection = new List<IContent>();
    foreach (IContent c1 in listOfAllItems)
    {
        foreach (IContent c2 in listOfAllItems1)
        {
            if (c1.ID == c2.ID)
            {
                intersection.Add(c1);
                break;
            }
            // list the content titles here
        }
    }


    Regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. LouiseBA
    LouiseBA avatar
    61 posts
    Registered:
    23 Mar 2010
    23 Apr 2010
    Link to this post
    Hey Ivan,

    Thanks, yes I saw another solution about this, however, the news item will be tagged by n number of tags, not necessarily two, so i would have to count the number of tags from the split function and do n number of seperate getContents, then do the intersection .. not very efficient. Bear in mind my page will have maybe 3 or 4 news item boxes.  If there is no other solution I will have to do that for now, but please advise .. also if you wouldnt mind any tips on my number 2 question..

    many thanks, Louise
Register for webinar
3 posts, 0 answered