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

Forums / Developing with Sitefinity / Filter Content Object

Filter Content Object

4 posts, 0 answered
  1. Richard Baugh
    Richard Baugh avatar
    201 posts
    Registered:
    22 Aug 2012
    06 Jul 2009
    Link to this post
    We were wanting to setup a custom search page for an instance of the news/generic content control. We wanted to allow the end user to search using a custom search interface. One of the features of the search interface would be to allow the end user to enter keywords that we would then search off of using a like statement. We know that we can use the ContentFilterBuilder to allow us to do a like search on the MetaFields, but what about doing a like search off of the main content object? Since this is suppose to be the meat of the item, how do we go about adding a filter for it?
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    08 Jul 2009
    Link to this post
    Hi Richard Baugh,

    The problem with this approach is that the content field is usually not a metafield, and the ContentFilterBuilder class works with metafields only. Having this in mind, I see two options here:

    First approach:. Define a new metafield, but do not show it in the user interface. You will save the value from the Content in this metafield, so this value (content text) will become searchable. This process should happen on every item save. You can hook up to the ContentManager.Executing method and the saving there.

    Second approach. You can do the search and filtering in several steps:

    1. Search the items by the available metafields only. We assume that you will end up with an IList of Generic Content items, right?
    2. Implement a foreach() method to iterate through each content item in the list, and perform:
    • String.Equals() for matching exact search phrase
    • String.Contains() for matching a text within the content
    • other rules like regular expression search, or like implementation
    Once you find an item that fits in the above criteria, add it in a second IList object.

    In the end, you should end up with a list containing items filtered by the default metafields, and the custom logic in the foreach() cycle.

    Let me know if I could be of further help.
    Regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Richard Baugh
    Richard Baugh avatar
    201 posts
    Registered:
    22 Aug 2012
    08 Jul 2009
    Link to this post
    Georgi,
    Thanks for the response. While the first option will work, it seems that there should be some way to filter items based off of the content object since this is the only required item for the generic content other than the ID. I would suggest that this be implmented in the v4 and wish I had caught this before.

    As for the second option, this will not always return the results desired. If the search value in question is not found in any MetaField, but is rather in the Content object of an item then you will get no results as you are only checking the content object if a result set is returned after filtering the MetaFields.

    Richard
  4. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    10 Jul 2009
    Link to this post
    Hello Richard Baugh,

    We will definitely thing for this suggestion - it sounds very reasonable.

    You are right about the second approach I suggested, I wasn't considering this scenario, but I am sure that with modification in the search logic (metafields first, content last to become metafield search and content search), it will work as well.

    Thanks for the suggestion though.

    Sincerely yours,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
4 posts, 0 answered