We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28033
    • 925 Posts
    IIRC, doesn’t this script allow for radio options? Like I could have a radio option for Gallery-only documents, etc.
      My Snippets
      -> PopUpChunk v1.0
      • 5811
      • 1,717 Posts
      ??? I don’t understand grin Is this post in the correct board : AjaxSearch ?
        • 25663 MODX Staff
        • 12,272 Posts
        I think Soshite is asking if it’s possible to have radio buttons to restrict where the search applies ... like only search blogs, or an image gallery, or site content.
          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          I would think a wrapper snippet would do the job; the wrapper would process the POST from the radio buttons and use runSnippet with the appropriate filters?
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 5811
            • 1,717 Posts
            I think Soshite is asking if it’s possible to have radio buttons to restrict where the search applies ... like only search blogs, or an image gallery, or site content.
            The format of &filter in version AS 1.8 is not very well adapted to be use with radio button or multiple-list form.

            Following your request, I plan with the next release 1.8.1 to add a general parameter named "whichSearch" to manage this kind of stuff.

            &whichSearch=`keyword` where keyword is a token defined by the programmer to do a link with a full AjaxSearch call snippet already defined in the configuration file.

            e.g: &whichSearch=`travels` with in the configuration file a use function to define the relationship with the appropriate AS search.
            For instance we could imagine the following AS search orders defined in the configuration file:
            function whichSearch($req){
            
              $searchParameters = array();
              
              switch($req){
                case "blog": // limited to blog documents
                  $searchParameters["parent"] = "124" // excludes all documents which haven't id 124 as ancestor (blog id root)
                  break;
                case "travels": // subset of the blog - articles regarding travels
                  $searchParameters["parent"] = "124" // excludes all documents which haven't id 124 as ancestor (blog id root)
                  $searchParameters["filter"] = "tv_content,7,travels"; // excludes all the document which haven't a TV value equal to "travels"
                  break;
                case "image gallery": // limited to image galleries
                  $searchParameters["parent"] = "300"; // excludes all documents which haven't id 300 as ancestor (image gallery id root)
                  break;
                case "china gallery": // limited to image galleries relating to china
                  $searchParameters["parent"] = "300"; // excludes all documents which haven't id 300 as ancestor (image gallery id root)
                  $searchParameters["filter"] = "tv_content,7,china"; // excludes all the document which haven't a TV value equal to "china"
                  break;
                case "comments"
                  $searchParameters["parent"] = "124" // excludes all documents which haven't id 124 as ancestor (blog id root)
                  $searchParameters["whereSearch"] = "content,jot"; // do the search in the jot elements, not only in documents
                  break;
                case "blog2": // limited to blog documents - different presentation
                  $searchParameters["parent"] = "124" // excludes all documents which haven't id 124 as ancestor (blog id root)
                  $searchParameters["extract"] = "5:introtext,content,tv_content" // uses these elements to set up a maximum of 5 extracts per search results
                  break;
                case "products": // search in the custom tables 
                  $searchParameters["whereSearch"] = "product,shop" // search in product and shop customs tables (defined in config file)
                  $searchParameters["extract"] = "name,shop_name,shop_address"; // uses these elements to set up a maximum of 5 extracts per search results
                  break;
              }
            
              return $searchParameters;
            }
            
            In the whichSearch user function, all the AS parameters should be redefined.
            The parameter whichSearch will be interpreted by POST variable from a form but could be also interpreted as a GET variable.
            If POST["whichSearch"] or GET["whichSearch"] exists, then all the AS parameter from the configuration file overwrite the AS parameters provided by the snippet call.

            Regarding Can a Firefox/IE search plugin be made using AjaxSearch? question. I think that it is feasable, but only by using the whichSearch parameter.
            In this case the plug-in open a window with the input form area and &advSearch parameter choice and by default call an url with the appropriate already defined whichSearch parameter.

            Thanks for your feedbacks about this solution/suggestion.
              • 5811
              • 1,717 Posts
              A demo of the mode "subSearch" (which allows multiple search in subdomains) is now available on the demo site. Try for instance "chin" as search term. Or "peter" or "des".

              The config file "subSearch" which contains the definition of search related to sub-domains is the following:
              <?php
              // For a global parameter initialisation use the following syntax $__param = 'value';
              // To overwrite parameter snippet call use $param = 'value';
              
                  function travel(){
                  
                    $config = array();
                    
                    // travel search definition
                    
                    $config['documents'] = '104'; 
                    $config['whereSearch'] = 'content:alias|jot|maxigallery';
                    $config['extract'] = '0';
                    $config['breadcrumbs'] = 'Breadcrumbs,showHomeCrumb:0,showCrumbsAtHome:1';
                        
                    return $config;
                  }
              
                  function portraits(){
                  
                    $config = array();
                    
                    // portraits search definition
                    
                    $config['documents'] = '155';
                    $config['whereSearch'] = 'content:alias|jot|maxigallery';
                    $config['extract'] = '0';
                    $config['breadcrumbs'] = 'Breadcrumbs,showHomeCrumb:0,showCrumbsAtHome:1';
                  
                    return $config;
                  }
                  
                  function travelbooks(){
                  
                    $config = array();
                    
                    // travelbook search definition
                    
                    $config['parents'] = '158';  
                    $config['whereSearch'] = 'content:pagetitle,content|tv|jot';
                    $config['extract'] = '99:content,jot_content';
                    $config['grabMax'] = '3';
                    $config['breadcrumbs'] = 'Breadcrumbs,showHomeCrumb:0,showCrumbsAtHome:1';
                        
                    return $config;
                  }
              
                  function unesco(){
                  
                    $config = array();
                    
                    // unesco search definition
                    
                    $config['parents'] = '61';
                    $config['whereSearch'] = 'content:pagetitle,content|tv';
                    $config['withTvs'] = '+:asTag1';
                    $config['breadcrumbs'] = 'Breadcrumbs,showHomeCrumb:0,showCrumbsAtHome:1';
                  
                    return $config;
                  }
              
              ?>
              And the layout template :
              [+as.showForm:is=`1`:then=`
              <form [+as.formId+] action="[+as.formAction+]" method="post">
                  <div id="ajaxSearch_radio">
                		<input type="radio" id="radio_oneword" name="advSearch" value="[+as.oneword+]" [+as.onewordChecked+] /><label for="radio_oneword">[+as.onewordText+]</label>
                		<input type="radio" id="radio_allwords" name="advSearch" value="[+as.allwords+]" [+as.allwordsChecked+] /><label for="radio_allwords">[+as.allwordsText+]</label>
                		<input type="radio" id="radio_exactphrase" name="advSearch" value="[+as.exactphrase+]" [+as.exactphraseChecked+] /><label for="radio_exactphrase">[+as.exactphraseText+]</label>
                		<input type="radio" id="radio_nowords" name="advSearch" value="[+as.nowords+]" [+as.nowordsChecked+] /><label for="radio_nowords">[+as.nowordsText+]</label>
              		</div>
              		<fieldset>
                  <label for="ajaxSearch_input">
                    <input id="ajaxSearch_input" class="cleardefault" type="text" name="search" value="[+as.inputValue+]" [+as.inputOptions+] />
                  </label>
                  <label for="ajaxSearch_submit">
                    <input id="ajaxSearch_submit" type="submit" name="sub" value="[+as.submitText+]" />
                  </label>
                  </fieldset>
                  <div id="ajaxSearch_subSearch">
                		<input type="radio" id="subSearch1" name="subSearch" value="travel,1" [+as.subSearch1Checked+] /><label for="subSearch1">Travel pictures gallery</label>
                		<input type="radio" id="subSearch2" name="subSearch" value="portraits,2" [+as.subSearch2Checked+] /><label for="subSearch2">Portrait picture gallery</label>
                		<input type="radio" id="subSearch3" name="subSearch" value="travelbooks,3" [+as.subSearch3Checked+] /><label for="subSearch3">Travel books</label>
                		<input type="radio" id="subSearch4" name="subSearch" value="unesco,4" [+as.subSearch4Checked+] /><label for="subSearch4">The Unesco courrier</label>
               		</div>
              </form>
              `+]
              [+as.showIntro:is=`1`:then=`
              <p class="ajaxSearch_intro" id="ajaxSearch_intro">[+as.introMessage+]</p>
              `+]
              [+as.showResults:is=`1`:then=`
              [+as.results+]
              `+]
                • 4245
                • 2 Posts
                I am trying to call a function from subSearch with a filter from the default config

                $config[’filter’] = ’tv_content,7,travels’;

                This seems not to be working correctly. Is this syntax correct?
                  • 5811
                  • 1,717 Posts
                  The documentation has some typos. The correct field name is "tv_value". So try :
                  $config['filter'] = 'tv_value,7,travels';
                  Let me know the results.
                    • 4245
                    • 2 Posts
                    I verified the other things such as $config[’parents’] again and those work.

                    [’filter’] still does nothing with tv_value. Do you have a working example?

                    I would be happy to share anything I make with this for future reference.
                      • 5811
                      • 1,717 Posts
                      In fact the correct use of filter should be:
                      $config['filter'] = 'tv_value,travels,7';

                      the correct use is: field,criterion,mode. mode is the last argurment not the second.

                      See: http://ditto.modxcms.com/tutorials/basic_filtering.html

                      Exclude a document if its value in the specified field does not contain the text of the criterion

                      So with this filter call all the documents which not contains the word filter in a TV will be exclude.