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

    I want to search all results between min TV an max TV. My example:

    my product min = 3;
    my product max = 6;

    If user want all products between 4 min and 7 max, advSearch doesn't find any match. I want a result because my product have 5 and 6 values.

    my custom filter test:
    <?php
    $a_age = array();
    $age_min = $_REQUEST['age_min'];
    $age_max = $_REQUEST['age_max'];
    for($i=$age_min; $i<=$age_max; $i++)
    {
    	$a_age[] = strval($i);
    }
    
    $andConditions = array(
    		'tv.sexe:=' => 'sexe:request:all',
    		'tv.age_minimum:IN' => 'age_min:request:'.implode(';', $a_age),
    		'tv.age_maximum:IN' => 'age_max:request:'.implode(';', $a_age),
    		'tv.prix_minimum:>=' => 'budget_min:request:none',
    		'tv.prix_maximum:<=' => 'budget_max:request:none',
    		'tv.categorie:=' => 'categories:request:all',
    		'tv.marque:=' => 'marques:request:all'
    );
    
    $qhDeclaration = array(
    		'qhVersion' => '1.2',
    		'andConditions' => $andConditions
    );
    
    $hook->setQueryHook($qhDeclaration);
    return true;
    


    but it doesn't work... help, thank's a lot and regards [ed. note: beejeridou last edited this post 13 years, 11 months ago.]
      • 5811
      • 1,717 Posts
      With a 'IN' clause you need to use a comma rather a semi-colon
      So 'age_min:request:'.implode(';', $a_age), can't work.

      Then if your form provide two values (min and max) to find all the results with tv value (age here) between these bounds do as follow:

      $a_age = array();
      $age_min = $_REQUEST['age_min'];
      $age_max = $_REQUEST['age_max'];
      for($i=$age_min; $i<=$age_max; $i++)
      {
          $a_age[] = strval($i);
      }
      
      $lst_age = implode(',', $a_age);
      $andConditions = array(
              'tv.age:IN' => $lst_age . ':integer',
      );
      Download queryHook example zip file from on http://www.revo.wangba.fr/advsearch-documentation.html and look at the example 7 (demo : http://www.revo.wangba.fr/faceted-search-7.html ).
      In this demo the IN clause is used for the selection of a subset of document id (French or English documents). Simply by using:
      $andConditions = array(
          'modResource.id:IN' => $lstids . ':integer'
      );


      Keep in mind, that you could use "request" type of value only if you get the value from the form without change. If you use your internal variable like lst_age, you can't use "request",

      To do the same thing (and probably with a faster sql request) you could use:
      $min = $_REQUEST['age_min'];
      $max = $_REQUEST['age_max'];
      
      $andConditions = array(
              'tv.e:=' => 'e:request:all',
      		....
      );
      if ($min <= $max) {
      	$andConditions['tv.age:>='] = $min . ':integer';
      	$andConditions['tv.age:<='] = $max . ':integer';
      }
        • 41642
        • 10 Posts
        Yeah thank's a lot for your response, but the syntaxe :
        $andConditions = array(
            'modResource.id:IN' => $lstids . ':integer'
        );
        

        dont't work... no php error, just no filters application.

        The better results for me is :

        $andConditions = array(
        		'tv.age_minimum:>=' => 'age_min:request:none',
        		'tv.age_maximum:<=' => 'age_max:request:none'
        );
        


        But : I would like find all products with all values in my array()... i'm crying ! wink
          • 41642
          • 10 Posts
          Example 7 use the 1.1 qhVersion. I've tested and it's good !

          Than'ks a lot !! for your help and Modx cms community !
            • 5811
            • 1,717 Posts

            Yes, you're right, an issue exist with 1.2 queryHook version. I didn't remenber of this issue..
            See https://github.com/Coroico/AdvSearch/issues/29 for a fix.
              • 41642
              • 10 Posts
              I'm sorry,

              This code return true if both values are in array(). I would like make a OR condition, is possible ?

              $andConditions = array(
              		'tv.age_minimum:IN' => $lst_age.':integer',
              		'tv.age_maximum:IN' => $lst_age.':integer'
              );
              


              In my perfect world :
              if tv.age_minimum:IN => $lst_age OR tv.age_maximum:IN return TRUE

              regards !
                • 41642
                • 10 Posts
                Hello,

                Documentation for version 1.1 is on download ?

                Regards
                  • 41642
                  • 10 Posts
                  Hello,

                  Resolved problem !

                      'tv.age_minimum:<=' => 'age_max:request:none',
                      'tv.age_maximum:>=' => 'age_min:request:none',
                  


                  Easy, not ? smiley

                  Thank's a lot for Coroico Help !!! very good person !