More in this section

Forums / Developing with Sitefinity / Custom Search by date range

Custom Search by date range

2 posts, 0 answered
  1. Gary
    Gary avatar
    6 posts
    04 Jul 2012
    12 Aug 2013
    Link to this post

    I'm going to build the custom search control that allow user to select a specific date range. But I can't find any resource about search by date range in Sitefinity. Thanks in advance.

  2. Bonny
    Bonny avatar
    58 posts
    11 Nov 2016
    14 Aug 2013
    Link to this post

    Thank you for contacting us.
    To solve your problem you will need to:

    1. Extend our "ContentInboundPipe" to add custom field to the exported objects - in your case the field can be of type "int" and the value will be "itemDate.ToString("yyyyMMdd")".
    In short - you will need to create a custom pipe inheriting from "ContentInboundPipe" and override the "SetProperties" method with something like this:
    override void SetProperties(WrapperObject wrapperObject, IContent contentItem)
       base.SetProperties(wrapperObject, contentItem);
       wrapperObject.AddProperty("MyPublicationDateField", int.Parce(date.ToString("yyyyMMdd")));

    Then you need to replace our pipe putting something like this code in "Application_Start" method in global.asax:
    PublishingSystemFactory.RegisterPipe(ContentInboundPipe.PipeName, typeof(MyCustomContentInboundPipe));

    2. You need to create a new SearchResults widget, inheriting from the default one.
    You need to override the "GetSearcher" method and return new implementation of "ISearcher" interface.
    Here is a sample code of "ISearcher" implementation:

    private class NewSearcher : Searcher
                public NewSearcher(SearchResults control)
                    : base(control)
                public override IEnumerable<IDocument> Search(string query, string catalogue, int skip, int take, out int hitCount)
                    var control = this.control;
                    var service = control.GetSearchService();
                    var compiledQuery = control.BuildSearchQuery(query, service);
    // At this point the query will be similar to "(Title:searchText Content:searchText )"
    // We need to add the date filter here
                    compiledQuery = compiledQuery .Substring(0, compiledQuery .Length - 1); // removing the last ')'
                    compiledQuery += "MyPublicationDateField:[20130813 TO 20130814])"; // here we add the date filter and close the expression with ')'
                    IResultSet result = service.Search(
                    hitCount = result.HitCount;
                    return result.SetContentLinks();

    When your widget is initialized, it will search for results with this field, matching the range that we set.

    Please contact us again if there is anything else you need to ask about this solution, or if you need further assistance.

    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
2 posts, 0 answered