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

Forums / Developing with Sitefinity / IMetaSearchInfo filtering

IMetaSearchInfo filtering

9 posts, 1 answered
  1. Tech
    Tech avatar
    26 posts
    Registered:
    13 Sep 2010
    23 May 2011
    Link to this post
    Greetings, 

    I have created a custom News provider and extended it with several fields, and the provider has been rolled out and live for a while now.  However, I need to make a change to that provider so that when someone deletes a news item from the externally-facing interface (not within the Sitefinity admin) it doesn't actually "delete" the item, it simply marks it as deleted, and filters it out.

    I can easily add the additional meta field, edit/add it in the interface and all that, but I am trying to set up filtering on the search so that it excludes anything that has the meta field Deleted set to true

    For example, I'm trying the following code to create my filters:

    IMetaSearchInfo[] filters = {
            new Telerik.Cms.Engine.MetaSearchInfo(MetaValueTypes.ShortText, "Category", category),
            new Telerik.Cms.Engine.MetaSearchInfo(MetaValueTypes.Boolean, "Deleted", false)
        };

    Of course, I didn't expect this to work exactly as is, because I imagine that the "Deleted" meta field is set to NULL in many cases (anything that precedes the addition of this field).  However, if I try to add a filter to include values of NULL (i.e., below), I get an error: "Nolics.ORMapper.Base.NolnetException: Erroneus query property"

    IMetaSearchInfo[] filters = {
            new Telerik.Cms.Engine.MetaSearchInfo(MetaValueTypes.ShortText, "Category", category),
            new Telerik.Cms.Engine.MetaSearchInfo(MetaValueTypes.Boolean, "Deleted", false),
            new Telerik.Cms.Engine.MetaSearchInfo(MetaValueTypes.Boolean, "Deleted", null)
        };

    I can only assume that this is because it doesn't know what to do with the null type here, but I have NO idea what type of NULL it wants.  Or if this is even the correct way to approach this.

    Any help would be great, thanks!
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    24 May 2011
    Link to this post
    Hello Phillip,

    You need to create content index provider that inherits from ContentIndexProvider or someone of the built-in index providers like NewsIndexProvider.

    Then you need to override GetContentToIndex where you have access to the content and you can remove the items from lucene segments.


    new Telerik.Cms.Engine.MetaSearchInfo(MetaValueTypes.Boolean, "Deleted", null

    will trow an error if the value is not set. You need to set the value to true or false, since the metakey is of type boolean.
    You can easily loop through all items and set the value explicitly to false if it is null or not true. Then you can inject filtering logic in the search provider.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Tech
    Tech avatar
    26 posts
    Registered:
    13 Sep 2010
    24 May 2011
    Link to this post
    Dimitry,

    I didn't even think about just looping through and cleaning the data through a script...the simplest solution is usually the first one to evade.

    Anyway, I'm giving that a try, but for some reason, my changes aren't saving properly.  Does the key need to be initialized somehow, or should a simple SetMetaData("Deleted", false) do the trick?  I tried this, but when I set it, then call the Newsmanager.Content.SaveContent(content_item) method, it doesn't seem to be saving that meta field unless it's already created.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    24 May 2011
    Link to this post
    Hello Phillip,

    Do you get the content item into a transaction ( cntmanager.GetContent)  before calling SetMetaData?

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Tech
    Tech avatar
    26 posts
    Registered:
    13 Sep 2010
    24 May 2011
    Link to this post
    Yep, here's my sample code:

    Telerik.News.NewsManager mgr = new Telerik.News.NewsManager("ChapterNews");
     
    System.Collections.IList news_list = mgr.Content.GetContent();
     
    foreach (Telerik.Cms.Engine.IContent item in news_list)
    {
        item.SetMetaData("Deleted", false);
        mgr.Content.SaveContent(item);
    }
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    24 May 2011
    Link to this post
    Hello Phillip,

    You get a list of items only, but not the object into transaction

    mgr.Content.GetContent(contentitemID);

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  7. Tech
    Tech avatar
    26 posts
    Registered:
    13 Sep 2010
    24 May 2011
    Link to this post
    Interesting...so you have to get each content item explicitly? This seems to have done the trick.

    Thanks much!
  8. Mike
    Mike avatar
    208 posts
    Registered:
    10 Dec 2007
    24 May 2011
    Link to this post
    Just a suggestion, but wouldn't it be easier to change the News.Expiration_Date for the item to a point in the past?  It seems to me the public newsview controls automatically filter out expired items (though this could be overridden).

    Regards,
    Mike Sharp
  9. Tech
    Tech avatar
    26 posts
    Registered:
    13 Sep 2010
    24 May 2011
    Link to this post
    Normally I would do something like this, but we're not actually expiring the content.  It's news-based, but needs to be available in a historic fashion as well. By marking them as "deleted", we can take them off and put them back in without altering any of the other data as well.
Register for webinar
9 posts, 1 answered