We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38713
    • 91 Posts
    Hi all i have a custom table which i want to do a faceted search in and have set the query hook up along with all other necessary bits but for some bizarre reason the form doesn't work with the query hook and i get:

    " There were no search results. Please try using more general terms to get more results. "

    but if i use the &init=`all` function AdvSearch returns results.

    So it seems that the query hook works but the form doesn't but the form is as i can see it should be.

    any ideas?

    <div class="top-search">
    	<form id="[[+asId]]_advsea-form" class="advsea-form" action="[[~[[+landing]]]]" method="[[+method]]">
    		<input type="hidden" name="id" value="[[+landing]]" />
        	<input type="hidden" name="asId" value="[[+asId]]" />
    		<div class="country">
    			<label>Country</label>
    			<select id="country" name="country">
    				<option value="all" selected="selected">Any Country</option>
    				<option value="United Kingdom">United Kingdom</option>
    				<option value="United States of America">United States of America</option>
    				<option value="France">France</option>
    				<option value="Spain">Spain</option>
    				<option value="Germany">Germany</option>
    				<option value="Portugal">Portugal</option>
    				<option value="Poland">Poland</option>
    				<option value="Switzerland">Switzerland</option>
    				<option value="Norway">Norway</option>
    				<option value="Denmark">Denmark</option>
    			</select>
    		</div>
    		<div class="new-used">
    			<input type="checkbox" value="New" name="condition[]" checked="checked" /> New
    			<input type="checkbox" value="Used" name="condition[]" checked="checked" /> Used
    		</div>
    		<div class="make">
    			<label>Make</label>
    			<select id="manufacturer" name="manufacturer">
    				<option value="all" selected="selected">All</option>
    				<option value="Agie">Agie</option>
    				<option value="Brother">Brother</option>
    				<option value="Charmilles">Charmilles</option>
    				<option value="Chmer">Chmer</option>
    				<option value="Fanuc">Fanuc</option>
    				<option value="Hitachi">Hitachi</option>
    				<option value="Japax">Japax</option>
    				<option value="Mitsubishi">Mitsubishi</option>
    				<option value="Ona">Ona</option>
    				<option value="Sodick">Sodick</option>
    			</select>
    		</div>
    		<div class="process">
    			<label>Process</label>
    			<select id="process" name="process">
    				<option value="all" selected="selected">Any EDM Process</option>
    				<option value="Drill EDM">Drill EDM</option>
    				<option value="Wire EDM">Wire EDM</option>
    				<option value="Mirco EDM">Mirco EDM</option>
    				<option value="Sink EDM">Sink EDM</option>
    			</select>
    		</div>
    		<div class="type">
    			<input type="checkbox" value="manual" name="type[]" checked="checked" /> Manual
    			<input type="checkbox" value="cnc" name="type[]" checked="checked" /> CNC
    		</div>
    		<div class="price">
    			<select id="price-from" name="price-from">
    				<option value="all" selected="selected">Min Price</option>
    				<option value="0">£0</option>
    				<option value="1000">£1000</option>
    				<option value="2000">£2000</option>
    				<option value="3000">£3000</option>
    				<option value="4000">£4000</option>
    				<option value="5000">£5000</option>
    				<option value="6000">£6000</option>
    				<option value="7000">£7000</option>
    				<option value="8000">£8000</option>
    				<option value="9000">£9000</option>
    				<option value="10000">£10,000</option>
    				<option value="20000">£20,000</option>
    				<option value="30000">£30,000</option>
    				<option value="40000">£40,000</option>
    				<option value="50000">£50,000</option>
    				<option value="60000">£60,000</option>
    				<option value="70000">£70,000</option>
    				<option value="80000">£80,000</option>
    				<option value="90000">£90,000</option>
    				<option value="100000">£100,000</option>
    				<option value="200000">£200,000</option>
    				<option value="300000">£300,000</option>
    			</select>
    			<select id="price-to" name="price-to">
    				<option value="all" selected="selected">Min Price</option>
    				<option value="1000">£1000</option>
    				<option value="2000">£2000</option>
    				<option value="3000">£3000</option>
    				<option value="4000">£4000</option>
    				<option value="5000">£5000</option>
    				<option value="6000">£6000</option>
    				<option value="7000">£7000</option>
    				<option value="8000">£8000</option>
    				<option value="9000">£9000</option>
    				<option value="10000">£10,000</option>
    				<option value="20000">£20,000</option>
    				<option value="30000">£30,000</option>
    				<option value="40000">£40,000</option>
    				<option value="50000">£50,000</option>
    				<option value="60000">£60,000</option>
    				<option value="70000">£70,000</option>
    				<option value="80000">£80,000</option>
    				<option value="90000">£90,000</option>
    				<option value="100000">£100,000</option>
    				<option value="200000">£200,000</option>
    				<option value="300000">£300,000</option>
    			</select>
    		</div>
    		<div class="button-set">
    			[[+liveSearch:isnot=`1`:then=`
    			<button id="[[+asId]]_advsea-submit" class="search" type="submit" name="sub" value="[[%advsearch.search? &namespace=`advsearch` &topic=`default`]]">
    				<span>Search</span>
    			</button>
    			`]]
    		</div>
    	</form>
    </div>




    [ed. note: alexmercenary last edited this post 13 years, 10 months ago.]
      Twitter @alexmercenary
      • 5811
      • 1,717 Posts
      If you use &init=`all` then no filtering is done. So this is not really relevant.

      In order to help you could you post the content of the queryHook used and the AdvSearch snippet call.
        • 38713
        • 91 Posts
        Hi Coroico

        Here's the queryHook:
        <?php
        $main = array(
            'package' => 'machines',
            'packagePath' => '{core_path}components/machines/model/',
            'class' => 'Machines',
        	'fields' => 'image , description , country , condition , manufacturer , process , type , price'
        );
        
        $andConditions = array(
        	'machines.country:=' => 'country:request:all',
        	'machines.condition:=' => 'condition:request:all',
        	'machines.manufacturer:=' => 'manufacturer:request:all',
        	'machines.process:=' => 'process:request:all',
        	'machines.type:=' => 'type:request:all',
        	'machines.price:>=' => 'price-from:request:all',
        	'machines.price:<=' => 'price-to:request:all'
        );
        
        $qhDeclaration = array( 
            'qhVersion' => 1.2,
        	'main' => $main,
            'andConditions' => $andConditions
        );
        
        $hook->setQueryHook($qhDeclaration);
        return true;


        and the snippet:
        [[!AdvSearch? 
        	&queryHook=`machinesSearchQHook`
        	&toPlaceholder=`machineSearchResults`
        	&init=`all`
        	&perPage=`50`
        	&tpl=`machineAdvSearchResult`
        ]]


        Merci
          Twitter @alexmercenary
          • 5811
          • 1,717 Posts
          You should specify where to do the search, so add the withFields line.
          The "fields" variable specify only the field values that will be displayed.

          $main = array(
              'package' => 'machines',
              'packagePath' => '{core_path}components/machines/model/',
              'class' => 'Machines',
              'fields' => 'image , description , country , condition , manufacturer , process , type , price',
              'withFields' => 'country , condition , manufacturer , process , type , price',
              'sortby' => 'Machines.country DESC, Machines.manufacturer ASC'
          );


          And check that the class name is 'Machines' with an upper first letter rather than 'machines'.

          I have added also a sortby clause as example.

          Remove &init=`all` from the advSearchForm except if you would like display all the results before to do any filtering.
            • 38713
            • 91 Posts
            Still doesn't work bro,

            The init=all is ok as i want to load all results to start with, but as soon as i hit search button i get the " There were no search results. Please try using more general terms to get more results. " message.

            Maybe it could be something to do with the fact i used migx to generate the custom table.

            But i am using the standard modx_ prefix.

            Thanks for all the help coroico.
              Twitter @alexmercenary
              • 38713
              • 91 Posts
              Right Chappppps,

              To whomever reads this...

              The lovely Brunaud emailed me and helped me get this sorted. It was absolutely stupid and my own fault (of course) but basically in your queryHook snippet where you are doing your search you are searching in custom tables make sure to use the Class name not package name.

              eg.

              in the &conditions above it would be:
              'Machines.country:=' => 'country:request:all',

              not:
              'machines.country:=' => 'country:request:all',


              as the uppercase Machines is the class name and the lowercase is the package name in this instance.

              Hope that helps someone and many thanks to Brunaud for this super duper search addon.
                Twitter @alexmercenary