We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28159
    • 22 Posts
    I’m having a bit of odd behavior with the filter in AjaxSearch (1.8.4).

    Everything works fine until I start filtering. This filter works:

    &filter=`id,33,2`

    This one doesn’t:

    &filter=`published,1,1|id,33,2`

    As soon as "published" is added to the filter, apparently everything else in the filter gets ignored. (That is, document id #33 does, in fact, show up.) I can add on dozens of "exclude this ID" fields with no problem -- it only breaks once "published" is introduced.


    ModX Evo 1.0.0. The actual Ajax call is from the landing page. I’ve tried adding the filter to the actual search call (embedded in the template, not the landing page), but that ignores the filter entirely.

    [!AjaxSearch? &ajaxSearch=`0` &AS_showForm=`0` &debug=`1` &filter=`published,1,1|id,24,2|id,31,2|id,32,2|id,33,2|id,35,2|id,37,2|id,38,2|id,39,2`!]
      • 5811
      • 1,717 Posts
      "published" is not a valid field for field.

      The fields that you could filter are: ’pagetitle’,’longtitle’,’description’,’alias’,’introtext’,’template’,’menutitle’,’content’,’publishedon’, ’tv_id’, ’tv_value’

      &filter=`id,33,2` is correct (#33 avoided).
      But with &filter=`published,1,1|id,33,2`, the application of the filter "published,1,1" provide an empty list of id. Empty list because the set of results that you would like filter don’t contain a field "published". Then by applying the filter `id,33,2` on an empty list of id you get an empty list.

      In any case the where clause of the ajaxSearch select executed for the search is like this :
      AND (sc.published=1) AND (sc.searchable=1) AND (sc.deleted=0) AND (sc.type='document') AND (sc.privateweb=0))
      This means that you always search in published, searchable, non-deleted, public (if not logged) document (type=document).

      In your case,&filter=`id,33,2` is enought to get all the published documents except the document #33
        • 28159
        • 22 Posts
        Ah, thankee. I wasn’t aware that Ajax by default only went for published things.

        That does raise a question though -- would you have to hack the core files if you wanted, for some reason, to include unpublished documents in searches?
          • 5811
          • 1,717 Posts
          As I am not convinced, that search in unpublised documents is a wished feature, yes, you have to hack the AS core.
          This is easy to do. See the initSearchContext function of the class/search.class.inc.php file (lines 589-594):
                    // documents should be published
                    $this->main['filters'][] = array(
                        'field' => 'published',
                        'oper' => '=',
                        'value' => '1'
                    );
          Remove or set as comment (//) these code lines.