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

    I'm new to modx and am doing some testing - I'm attempting (and failing!) to use AdvSearch to return results from data stored by the FAQ Manager package. AdvSearch is installed correctly and returning results from what I would term 'static resources' but, no go on the FAQ content.

    I'm trying to use a queryhook as suggested by the package author at http://www.revo.wangba.fr/custom-package-dvd-shop/ (site is down at the moment, but google has a cached version).

    my queryhook is a snippet titled FAQHook.

    $main = array(
        'package' => 'faqman',
        'packagePath' => '{core_path}components/faqman/model/',
        'class' => 'faqManItem',
        'fields' => 'question,answer',
        'withFields' => 'question,answer'
    );
    
    
    // set the query hook declaration
    $qhDeclaration = array(
        'qhVersion' => '1.2',       // version of queryHook - to manage futures changes
    	'main' => $main,
    );
    
    $hook->setQueryHook($qhDeclaration);
    
    return true;

    The sql tables for the FAQ are populated. I was under the impression that simply calling something like:
    [[!AdvSearchForm? &landing=`18`&queryHook=`FAQHook`]]

    would give me valid output, where resource 18 contains:
    <h2>Results</h2>
    [[!AdvSearch]]


    I get results but not from anything stored in the FAQ Manager tables.
    Any ideas on what I'm doing wrong or how I can debug this?

    (Using modX Revo 2.2.14-pl, FAQ Manager 1.1.0, AdvSearch 1.0.1)

    thanks.

    This question has been answered by nir-z. See the first response.

    • discuss.answer
      • 36996
      • 211 Posts
      Hi laforge,
      I think that the queryHook belongs in the AdvSearch snippet, not the AdvSearchForm

      [[!AdvSearchForm? &landing=`18`]]
      


      and

      <h2>Results</h2>
      [[!AdvSearch? &queryHook=`FAQHook`]]
      
        • 47832
        • 3 Posts
        Quote from: nir-z at Jun 02, 2014, 08:53 AM
        Hi laforge,
        I think that the queryHook belongs in the AdvSearch snippet, not the AdvSearchForm

        Thanks for the help Nir. You are right and that's a rookie mistake from me sad

        I had to make a few more tweaks to get advSearch playing nicely with Faq Manager so I'm going to post them below for anyone whose search leads them here.

        After fixing up the location of the queryhook call I was still getting no output. Using the very handy debug parameter:
        [[!AdvSearch? &queryHook=`FAQHook`&debug=`1`]]

        meant I could see the SQL query output on the page, however when I put it through a mysql client it came up with

        SELECT DISTINCT `faqManItem`.`id`, `faqManItem`.`question`, `faqManItem`.`answer`  
        FROM `faqman_items` AS `faqManItem`

        <snip>
        ERROR 1146 (42S02): Table 'modx.faqman_items' doesn't exist
        .

        The actual table is modx_faqman_items so I fixed that by adding 'tablePrefix' => 'modx_',
        to the queryHook main object.

        Again I got SQL errors relating to unknown columns. After viewing the example linked in my post above I was under the impression that the fields, withfields and sortby parameters were optional for a queryHook . Apparently not as without them AdvSearch will use the defaults values from withFields and sortbyin the sql query. So, the working queryHook looks like this:

        $main = array(
            'package' => 'faqman',
            'packagePath' => '{core_path}components/faqman/model/',
            'class' => 'faqManItem',
            'tablePrefix' => 'modx_',
            'fields' => 'question,answer',
            'withFields' => 'question,answer',  
            'sortby' => 'question DESC'
        );
        
        // set the query hook declaration
        $qhDeclaration = array(
            'qhVersion' => '1.2',       // version of queryHook - to manage futures changes
        	'main' => $main
        );
        
        $hook->setQueryHook($qhDeclaration);
        return true;


        The only caveat is that it ONLY searches FAQ content. Anyone have any ideas on how to merge this with site wide search content? This is a very comprehensive package and most of the doco seems to be on a website that's down at the moment..