We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37108
    • 80 Posts
    I'm working on building a search that looks in the main content, some tvs, and a joined custom table. At first I was getting a silent error because my table uses the same prefix as the modx ones. A little research and examination of the classes led me to the need to add the "tablePrefix" key/val to the "joined" array in my query hook. I caught on to the error by echoing out the built query via the nicequery($c) method (inserted in advsearchresults.class.php around line 155, right before if (empty($this->queryHook['stmt']))...) and running it in a stand alone mysql editor (Navicat). The second time I ran nicequery($c)—after adding the correct prefix—the resulting query showed the results I was expecting (in Navicat). Yet there are still no results when trying the search via the site search page. Any ideas on how this could happen?

    The call:
    [[!AdvSearch? 
        &method=`get` 
        &queryHook=`CS-SearchFiltersHook` 
        &withTVs=`article-title,article-subtitle,article-sidebar,article-readinglist,article-tags-generations` 
        &includeTVs=`article-title,article-subtitle,article-sidebar,article-readinglist`
        &perPage=`5`  
        &showExtract=`3:content,vcSections_sectioncontent,article-sidebar,introtext,article-readinglist` 
        &addCss=`0` 
        &tpl=`custom-as-result` 
        &containerTpl=`custom-as-results` 
        &paging1Tpl=`custom-as-paging`
    ]]
    


    The hook:
    $joined = array(
    	array(
    		'package'=>'varcontent',
    		'tablePrefix'=>'{std}',
    		'class'=>'vcSections',
    		'packagePath'=>'{core_path}components/varcontent/model/',
    		'fields'=>'sectioncontent',
    		'withFields'=>'sectioncontent,sectionheading',
    		'joinCriteria'=>'vcSections.resource_id = modResource.id'
    	)
    );
    
    $params = array(
    	'qhVersion'=>'1.2',
    	'joined'=>$joined
    );
    $hook->setQueryHook($params);
    
    return true;
    


    The custom table's model:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <model version="1.1" package="varcontent" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" phpdoc-package="varcontent" phpdoc-subpackage="model">
    
        <object class="vcSections" table="cct_vc_sections" extends="xPDOSimpleObject">
    
            <field key="sectionheading" dbtype="varchar" precision="255" phptype="string" null="false" default="" index="fulltext" indexgrp="sections_ft_idx" />
            <field key="sectionshortheading" dbtype="varchar" precision="255" phptype="string" null="true" default="" index="fulltext" indexgrp="sections_ft_idx" />
    		<field key="sectioncontent" dbtype="text" phptype="string" null="false" index="fulltext" indexgrp="sections_ft_idx" />
    		
    		<field key="sectionindex" dbtype="smallint" precision="2" attributes="unsigned" phptype="integer" null="true" default="0" />
    
    		<field key="resource_id" dbtype="int" precision="11" phptype="integer" null="false" default="" />
    
            <field key="createdon" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="" />
            <field key="modifiedon" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="true" default="" />
    
    		<index alias="sections_ft_idx" name="sections_ft_idx" primary="false" unique="false" type="FULLTEXT">
                <column key="sectionheading" length="" collation="A" null="false" />
                <column key="sectionshortheading" length="" collation="A" null="true" />
                <column key="sectioncontent" length="" collation="A" null="false" />
            </index>
    		
    		<aggregate alias="Resource" class="modResource" local="resource_id" foreign="id" cardinality="one" owner="foreign" />
    
        </object>
    
        [...A couple more objects stripped out for simplicity's sake...]
    
    </model>
    
    [ed. note: smg6511v2 last edited this post 10 years, 3 months ago.]