We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50960
    • 17 Posts
    I have been researching for a couple days now and I cannot seem to understand how to accomplish what I need. My Knowledge on Snippet development is limited. I have determined I need to use AdvSearch with QueryHooks. But I am lost where to start. Never used AdvSearch only SimpleSearch.

    Tagger is setup with 3 different tagger groups [Type, Service L1, Service L2] to be used on my sites resources (blogs, news, articles) pages.

    I will have a resources.html page that will show ALL available resources under Resources [19]. Each resource will be tagged appropriately in the Template Variable using Tagger. I will show available tags under each group on the side menu (sort-of a search by filtering menu) and need to Filter the results on the page. This will occur either by submitting a button to "Apply Filters" or it will happen "Live" as tags are selected. The Submit button is what I need working, but having it live filter would be ideal. Any guidance on where to start would be appreciated.

    I have some code to reference:
    [Page]
    [[!AdvSearchForm? &tpl=`AdvanceSearchForm_tpl`]]
    <hr>
    <h2>Results</h2>
    <p>[[!AdvSearch? &parents=`19`&queryHook=`qhFilter`]]


    [AdvanceSearchForm_tpl]
    <form class="advsea-search-form" action="[[~[[+landing]]]]" method="[[+method]]">
      <fieldset>
        <input type="hidden" name="id" value="[[+landing]]" />
        <input type="hidden" name="asId" value="[[+asId]]" />
    
    	<div class="group1">
    	  <label>Type</label>
    	  <select id="group1" name="group1">
    		<option value="" selected="selected">-</option>
    		[[TaggerGetTags? &ids=`[[!GetIds? &ids=`c19`]]` &groups=`1` &showUnused=`0` &rowTpl=`@INLINE <option value="[[+tag]]">[[+tag]]</option>`]]
    	  </select>
    	</div>
    	
    	<div class="group2">
    	  <label>Service L1</label>
    	  <select id="group2" name="group2">
    	  	<option value="" selected="selected">-</option>
    		[[TaggerGetTags? &ids=`[[!GetIds? &ids=`c19`]]` &groups=`2` &showUnused=`0` &rowTpl=`@INLINE <option value="[[+tag]]">[[+tag]]</option>`]]
    	  </select>
    	</div>
    	
    	<div class="group3">
    	  <label>Service L2</label>
    	  <select id="group3" name="group3">
    	  	<option value="" selected="selected">-</option>
    		[[TaggerGetTags? &ids=`[[!GetIds? &ids=`c19`]]` &groups=`3` &showUnused=`0` &rowTpl=`@INLINE <option value="[[+tag]]">[[+tag]]</option>`]]
    	  </select>
    	</div>
    	
        <input type="submit" name="sub" value="[[%advsearch.search? &namespace=`advsearch` &topic=`default`]]" />
      </fieldset>
    </form>
    [[+resultsWindow]]


    [qhFilter]
    <?php
    # Main for MODX
    $main = array(
        'package' => 'modx',
        'packagePath' => '{core_path}model/',
        'class' => 'modResource',                         
        'fields' => 'id',                        
        'withFields' => 'id',                    
        'sortby' => 'TaggerTagResource.tag DESC',
        'tablePrefix' => 'modx_'
    );
     
    # Join with Tagger table
    $joined = array(
        array(
            'package' => 'tagger',        
            'packagePath' => '{core_path}components/tagger/model/', 
            'class' => 'TaggerTagResource',
            'withFields' => 'resource, tag',
            'fields' => 'resource, tag',
            # On the resource ID
            'joinCriteria' => 'modResource.id = TaggerTagResource.resource',
            'tablePrefix' => 'modx_'
        )
    );
     
    $andConditions = array(
        # One tag/option
        'TaggerTagResource.tag:=' => '2',
        # Another tag/option
        'TaggerTagResource.tag:=' => '4'
    );
     
    # set the query hook declaration
    $qhDeclaration = array(
        'qhVersion' => '1.3',
        'main' => $main,
        'joined' => $joined,
        'andConditions' => $andConditions
    ); 
    $hook->setQueryHook($qhDeclaration);
     
    return true;
      Tink!
    • try to add
      &debug=`1`
      in the snippet's call, and identify the problem from error log.
        Rico
        Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
        MODx is great, but knowing how to use it well makes it perfect!

        www.virtudraft.com

        Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

        Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

        Maintainter/contributor of Babel

        Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
        • 50960
        • 17 Posts
        Form with debug. A few errors listed
        [2018-12-10 17:54:42] (DEBUG IN ADVSEARCH::LOADDEFAULTCONFIGS @ /PAAS/C0231/WWW/CORE/COMPONENTS/ADVSEARCH/MODEL/ADVSEARCH/ADVSEARCH.CLASS.PHP : 113)
        
        [AdvSearch] System environment: Array
        (
            [MODx version] => 2.6.5-pl
            [Php version] => 7.1.25
            [MySql version] => 5.6.38-83.0
            [AdvSearch version] => 2.0.0 beta2
        )
        [2018-12-10 17:54:42] (DEBUG IN ADVSEARCH::LOADDEFAULTCONFIGS @ /PAAS/C0231/WWW/CORE/COMPONENTS/ADVSEARCH/MODEL/ADVSEARCH/ADVSEARCH.CLASS.PHP : 114)
        
        [AdvSearch] Config parameters before checking: Array
        (
            [corePath] => /paas/c0231/www/core/components/advsearch/
            [assetsUrl] => assets/components/advsearch/
            [chunksPath] => /paas/c0231/www/core/components/advsearch/elements/chunks/
            [modelPath] => /paas/c0231/www/core/components/advsearch/model/
            [addCss] => 1
            [addJQuery] => 1
            [addJs] => 1
            [ajaxResultsId] => 0
            [asId] => as0
            [clearDefault] => 1
            [debug] => 1
            [help] => 1
            [jsSearchForm] => assets/components/advsearch/js/advsearchform.min.js
            [jsJQuery] => assets/components/advsearch/js/jquery-1.7.1.min.js
            [landing] => 0
            [liveSearch] => 0
            [method] => GET
            [opacity] => 1
            [searchIndex] => search
            [toPlaceholder] => 
            [tpl] => AdvanceSearchForm_tpl
            [urlScheme] => -1
            [withAjax] => 0
            [charset] => UTF-8
        )
        [2018-12-10 17:54:42] (ERROR @ /PAAS/C0231/WWW/CORE/MODEL/MODX/MODX.CLASS.PHP : 990)
        
        `` is not a valid integer and may not be passed to makeUrl()
        [2018-12-10 17:54:42] (ERROR IN RESOURCE 19 @ /PAAS/C0231/WWW/CORE/MODEL/MODX/MODPARSER.CLASS.PHP : 1372)
        
        Bad link tag `` encountered
        [2018-12-10 17:54:42] (ERROR @ /PAAS/C0231/WWW/CORE/MODEL/MODX/MODPARSER.CLASS.PHP : 540)
        
        Could not find snippet with name GetIds.
        [2018-12-10 17:54:42] (ERROR @ /PAAS/C0231/WWW/CORE/MODEL/MODX/MODPARSER.CLASS.PHP : 540)
        
        Could not find snippet with name GetIds.
        [2018-12-10 17:54:42] (ERROR @ /PAAS/C0231/WWW/CORE/MODEL/MODX/MODPARSER.CLASS.PHP : 540)
        
        Could not find snippet with name GetIds.
        [2018-12-10 17:54:42] (DEBUG IN ADVSEARCHFORM::OUTPUT @ /PAAS/C0231/WWW/CORE/COMPONENTS/ADVSEARCH/MODEL/ADVSEARCH/ADVSEARCHFORM.CLASS.PHP : 315)
        
        [AdvSearch] Elapsed time:0.0315s



        Results with debug:
        [2018-12-10 17:54:42] (WARN @ /PAAS/C0231/WWW/CORE/CACHE/INCLUDES/ELEMENTS/MODSNIPPET/155.INCLUDE.CACHE.PHP : 31)
        
        PHP notice: Undefined index: asId
        [2018-12-10 17:54:42] (WARN @ /PAAS/C0231/WWW/CORE/COMPONENTS/ADVSEARCH/MODEL/ADVSEARCH/ADVSEARCH.CLASS.PHP : 58)
        
        PHP notice: Undefined index: withAjax
        [2018-12-10 17:54:42] (DEBUG IN ADVSEARCH::LOADDEFAULTCONFIGS @ /PAAS/C0231/WWW/CORE/COMPONENTS/ADVSEARCH/MODEL/ADVSEARCH/ADVSEARCH.CLASS.PHP : 113)
        
        [AdvSearch] System environment: Array
        (
            [MODx version] => 2.6.5-pl
            [Php version] => 7.1.25
            [MySql version] => 5.6.38-83.0
            [AdvSearch version] => 2.0.0 beta2
        )
        [2018-12-10 17:54:42] (DEBUG IN ADVSEARCH::LOADDEFAULTCONFIGS @ /PAAS/C0231/WWW/CORE/COMPONENTS/ADVSEARCH/MODEL/ADVSEARCH/ADVSEARCH.CLASS.PHP : 114)
        
        [AdvSearch] Config parameters before checking: Array
        (
            [corePath] => /paas/c0231/www/core/components/advsearch/
            [assetsUrl] => assets/components/advsearch/
            [chunksPath] => /paas/c0231/www/core/components/advsearch/elements/chunks/
            [modelPath] => /paas/c0231/www/core/components/advsearch/model/
            [parents] => 19
            [queryHook] => qhFilter
            [debug] => 1
            [contexts] => web
            [fields] => pagetitle,longtitle,alias,description,introtext,content
            [charset] => UTF-8
        )
          Tink!