We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22851
    • 805 Posts
    Hi there.

    I am getting a parse error with AjaxSearch 1.8.2-a when the search has no results. This is on a system with PHP Version 5.1.6. I don’t think it’s a problem of compatibility with an older version of PHP however.

    Here is the call
    [!AjaxSearch? &AS_showResults=`0` &AS_showForm=`1` &language=`english` &debug=`0` &ajaxSearch=`0` &ajaxSearchType=`0` &hideMenu=`2` &hideLink=`1` &depth=`10` &grabMax=`10` &AS_landing=`44` &parents=`31` &filter=`type,reference,2|searchable,1,1` &mbstring=`0` !]

    and here is the parse error
    « MODx Parse Error »
    
    MODx encountered the following error while attempting to parse the requested resource:
    « PHP Parse Error »
     
    PHP error debug
      Error:	array_filter() [function.array-filter]: The first argument should be an array	 
      Error type/ Nr.:	Warning - 2	 
      File:	.../modx-0.9.6.3/assets/snippets/ajaxSearch/classes/filter.class.inc.php	 
      Line:	34	 
      Line 34 source:	 $resource = array_filter($resource, array($this, "basicFilter"));	 
     
    Parser timing
      MySQL:	0.1333 s	(28 Requests)
      PHP:	0.9415 s	 
      Total:	1.0748 s
    


    EDIT:
    Further investigation shows that this error goes away when the &filter=`type,reference,2|searchable,1,1` argument is removed.
      YAMS: Yet Another Multilingual Solution for MODx
      YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
      Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
      • 5811
      • 1,717 Posts
      Hi Paul,

      What’s the meaning of
      &filter=`type,reference,2|searchable,1,1`
      Regarding http://ditto.modxcms.com/tutorials/basic_filtering.html you would like exclude all documents of type reference or documents not (equal to) searchable
      By default &hideLink=`1` which exlude all the links (reference documents)
      Non searchable documents are always excluded.

      In the ajaxSearch_log.txt file, search the SELECT statement. you will get something with : ... AND (sc.searchable=1) AND (sc.deleted=0) AND (sc.type=’document’) ... with default values of &hideLink


      As by default &hideMenu=`2`, &depth=`10`, &hideLink=`1` and ajaxSearchType depreacated, the hereafter snippet call is enougth:
      [!AjaxSearch? &AS_showResults=`0` &AS_showForm=`1` &language=`english` &debug=`0` &ajaxSearch=`0`  &grabMax=`10` &AS_landing=`44` &parents=`31` &mbstring=`0` !]



      Otherwise, for the moment I can’t explain your parse error sad
        • 22851
        • 805 Posts
        You’re right. &hideLink=`1` is sufficient to achieve what I wanted. So, I don’t need the filter parameter and so can avoid the parse error.

        Thank you!
          YAMS: Yet Another Multilingual Solution for MODx
          YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
          Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
          • 5811
          • 1,717 Posts
          The reason of the parse error comes from snippets/ajaxSearch/classes/search.class.inc.php - around line 1272:
                // get the rows linked to the unfiltered listIDs
                $rs = $this->doSearch();
                while ($row = mysql_fetch_assoc($rs)) {
                  $rows[] = $row;
                }
                // filter the listIDs
                if (!class_exists('asFilter')) include_once AS_PATH . "classes/filter.class.inc.php";
                $filter = new asFilter();
                $rows = $filter->execute($rows,$parsedFilters);
                // filter the listIDs
                if (!class_exists('asFilter')) include_once AS_PATH . "classes/filter.class.inc.php";
                $filter = new asFilter();
                $rows = $filter->execute($rows,$parsedFilters);
                if (count($rows) > 0) {
                  foreach ($rows as $key => $value) {
                    $filteredIDs[] = $value[$this->main['id']];
                  }
                  $this->listIDs = implode(',',$filteredIDs);       
                }
          

          When the search has no results, $rows[] is not initialised.

          As I haven’t reproduced the parse error (I use Php 5.2.8 ) Could you replace the above code by:
                // get the rows linked to the unfiltered listIDs
                $rs = $this->doSearch();
                if ($modx->getRecordCount($rs) > 0){
                  $rows = array();
                  while ($row = mysql_fetch_assoc($rs)) {
                    $rows[] = $row;
                  }
                  // filter the listIDs
                  if (!class_exists('asFilter')) include_once AS_PATH . "classes/filter.class.inc.php";
                  $filter = new asFilter();
                  $rows = $filter->execute($rows,$parsedFilters);
                  if (count($rows) > 0) {
                    foreach ($rows as $key => $value) {
                      $filteredIDs[] = $value[$this->main['id']];
                    }
                    $this->listIDs = implode(',',$filteredIDs);       
                  }
                }
          
          and let me know the results. Thanks.
            • 22851
            • 805 Posts
            Yes. That works. Thanks again!
              YAMS: Yet Another Multilingual Solution for MODx
              YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
              Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
              • 5811
              • 1,717 Posts
              Issue registered as AJAXSEARCH-31

              Fixed with AjaxSearch1.8.2b