Smart Search calendar filter

Wojciech Małek asked on January 9, 2017 14:33

I'm trying to create a search with Date From and Date To filters. I tried to use two Smart Search Filters with Filter Mode Textbox but I just can't pass inserted values to the search engine. I was googling around and have found nothing and in examples I can only find Date ranges using dropdown list ( in exmaples of corporate site) which are preconfigured (user is not inserting dates).

Maybe someone has a knowledge how to create date range search using Kentico's Smart search ?

Recent Answers


Brenden Kehren answered on January 9, 2017 15:21 (last edited on December 10, 2019 02:30)

What about something like this:

+_created;[{%ToSearchDateTime(CurrentDateTime.AddDays(-7))|(identity)GlobalAdministrator%}];Past week

It's in the documentation here in the examples for conditional filters.

0 votesVote for this answer Mark as a Correct answer

Wojciech Małek answered on January 9, 2017 15:29 (last edited on January 9, 2017 15:30)

Hi Brenden!

Thanks for the quick response but it's not what I'm looking for ( I think so ). The value you've provided is fine for checkbox or dropdown list or radio buttons as an option to be choosen. I want user to be able to provide both datetimes (start and end of date range) so I think the best filter mode to use is Textbox.

It's not working but logically should be more like this: +_created;[{%ToSearchDateTime(DATE_FROM)%} TO {%ToSearchDateTime(DATE_TO)%}];nothing where DATE_FROM and DATE_TO should be inserted by user.

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on January 9, 2017 22:54 (last edited on December 10, 2019 02:30)

If you aren't creating a custom smart search filter (should be documentation and examples in the documentation of kentico), then you can use query string macros to apply a filter.

{% Convert.todatetime(mystartdatequerystringparam, date time.now) |(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

Wojciech Małek answered on January 10, 2017 11:03

I wouldn't like to have one of the filters to be in URL. I believe I have to create custom smart search filter then.

0 votesVote for this answer Mark as a Correct answer

Wojciech Małek answered on January 12, 2017 14:57 (last edited on December 10, 2019 02:30)

It was so close to complete this without custom web part.

+_created:([{0} TO {%ToSearchDateTime(DateTime.MaxValue)|(identity)GlobalAdministrator%}])

is the code for the FROM date. Unfortunately, Text Box Filter changes user input from STRING to :(STRING)

Finished with cloning Smart Search filter web part and changing this a little bit.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.