We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36467
    • 73 Posts
    I am using advsearch snippet to list search results.
    [[!AdvSearch? 
    &extractLength=`220` 
    &queryHook=`ArticleSearchQHook` 
    &extractEllipsis=`.` 
    &contexts=`web,tech,data,main` 
    &tpl=`articleSearchResult` 
    &perPage=`10` 
    &minChars=`2` 
    &withTVs=`docGroup,post_category,post_subcategory,category`
    &fields=`pagetitle,longtitle,description,introtext,content,publishedon`]]
    


    i want to show results which are published between given date range. So i am using 2 text boxes with datepicker plugin. I am able to see the selected dates in URl like below

    advanced-search-result?id=9817&asId=as0&pubfromdate=2012-11-01&pubtodate=2012-12-18&search=tech&sub=Search


    How can i filter result based on date range ? ( Actually, Problem is not ADVsearch problem is i still dont understand how TV's can be useful in such cases)

    There is another issue, publishedon column stores date in "timestamp" format as you know and my textfields accepts "DMY" format, but thats not a big deal i think, i can handle that issue.

    This question has been answered by amitpatil. See the first response.

    [ed. note: amitpatil last edited this post 13 years, 9 months ago.]
    • discuss.answer
      • 36467
      • 73 Posts
      Found the solution, So here i am posting it for my own documentation as well as if someone happens to face same thing it will be helpful.

      I added below code in ArticleSearchQHook snippet
      if (!empty($_REQUEST['pubfromdate']) && $pubfromdate = strtotime($_REQUEST['pubfromdate'])) {
          $andConditions['modResource.publishedon:>'] = "{$pubfromdate}:numeric";
      }
      
      if (!empty($_REQUEST['pubtodate']) && $pubtodate = strtotime($_REQUEST['pubtodate'])) {
          $andConditions['modResource.publishedon:<'] = "{$pubtodate}:numeric";
      }


      So my complete code for ArticleSearchQHookbecame

      $andConditions = array();
      
      if (!empty($_REQUEST['pubfromdate']) && $pubfromdate = strtotime($_REQUEST['pubfromdate'])) {
          $andConditions['modResource.publishedon:>'] = "{$pubfromdate}:numeric";
      }
      
      if (!empty($_REQUEST['pubtodate']) && $pubtodate = strtotime($_REQUEST['pubtodate'])) {
          $andConditions['modResource.publishedon:<'] = "{$pubtodate}:numeric";
      }
      
      $andConditions['tv.post_category:MATCH'] = 'ctg:request:all';
      $andConditions['tv.post_subcategory:MATCH'] = 'type:request:all';
      
      $qhDeclaration = array(
          'qhVersion' => '1.2',
      	'andConditions' => $andConditions
      );
      
      $hook->setQueryHook($qhDeclaration);
      return true;