+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Filter content

Filter content

6 posts, 0 answered
  1. Bruno Michels
    Bruno Michels avatar
    125 posts
    Registered:
    16 Apr 2010
    26 Jul 2010
    Link to this post
    I have the following objects

    Guid[] Contents;    // ContentIDs selected by the admin
    Guid[] Categories;  //
    Guid[] Tags;        //

    I want to get all contents that have one of the IDs of the Contents, Categories and Tags.

    For example

    var manager = new ContentManager("News");
    var filters = new List<IMetaSearchInfo>();
     
    filters.Add(new MetaSearchInfo(MetaValueTypes.DateTime, "Publication_Date", DateTime.Now, SearchCondition.LessOrEqual, JoinType.And));
    filters.Add(new MetaSearchInfo(MetaValueTypes.DateTime, "Expiration_Date", DateTime.Now, SearchCondition.GreaterOrEqual, JoinType.And));
     
    foreach (var cc in Contents)
    {
        filters.Add(new MetaSearchInfo(MetaValueTypes.Guid, "ID", cc, JoinType.Or));
    }
     
    var test = manager.GetContent("Publication_Date", filters.ToArray());

    Without adding the filter for ID it works.

    How can I add a filter to content, category and tags?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    26 Jul 2010
    Link to this post
    Hi Bruno Michels,

    OR condition is not supported by Nolics data layer. You can use IN instead. You can filter by Tag.Name - GetContent does not have a method where you can filter by Tag.ID. For categories you should also use Name property.

    Kind 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. Bruno Michels
    Bruno Michels avatar
    125 posts
    Registered:
    16 Apr 2010
    26 Jul 2010
    Link to this post
    Ok...

    For the Contents I will use the parameter on GetContent method...
    Category Name works with the filter...

    But what about the tags? How can I filter to get only the content that have, for example, "Tag1" and "Tag2" ?

    The following is not working, and I am sure there is content with this tag

    filters.Add(new MetaSearchInfo(MetaValueTypes.ShortText, "Tag.Name", "something", JoinType.In));
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    26 Jul 2010
    Link to this post
    Hi Bruno Michels,

    Here is the correct condition

    filterBuilder.AddFilter(new ContentFilterStatement("Tag.Name", "MyTag1", ContentFilter.Condition.Equal, ContentFilter.JoinType.And));
     
    filterBuilder.AddFilter(new ContentFilterStatement("Tag.Name", "MyTag2", ContentFilter.Condition.Equal, ContentFilter.JoinType.And));
     
     
    filterBuilder.AddFilter(new ContentFilterStatement("Tag.Name", "MyTag3", ContentFilter.Condition.Equal, ContentFilter.JoinType.And));


    You can use directly method of GontentManager - GetTags(Guid contentId) - Get all Tags for a specific content item by passing its ID


    Greetings,
    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
  5. Andrew
    Andrew avatar
    202 posts
    Registered:
    05 Jun 2009
    02 Sep 2010
    Link to this post

    Can you please explain how to use the filterbuilder as opposed to the

    var filters = new List<IMetaSearchInfo>();


    I cannot find anything in the developer’s manual about it.

  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    02 Sep 2010
    Link to this post
    Hi Andrew,

    ContentFilterBuilder works with controls that implement IFilterableContentControl interface.
    ContentFilterBuilder has a method AddFilter that adds one filter statement to the filterExpression.
    You have to crate a ContentFilterStatement

    overloads

    • public ContentFilterStatement(string leftOperand, string rightOperand, ContentFilter.Condition condition, ContentFilter.JoinType joinType)
    • public ContentFilterStatement(string leftOperand, string rightOperand, ContentFilter.Condition condition)
    • public ContentFilterStatement(string leftOperand, ContentFilter.Condition condition)
    • public ContentFilterStatement(string leftOperand, ContentFilter.Condition condition, ContentFilter.JoinType joinType)

    In its basis ContentFilterBuild uses IMetaSearchInfo for the metakeys. The benefit of ContentFilterBuild is that you can filter by Tags and some properties like ParenID.


    Best wishes,
    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
Register for webinar
6 posts, 0 answered