We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21560
    • 145 Posts
    MEANT FOR URL REWRITE SITES! (sorry for the caps)
    A non URL Rewrite site would not have any use for this. Since the pages would be by their number ID, which is useless to search on.

    Concept:

    Since I couldn’t find a dynamic search that worked with URL Rewriteable pages, I made it myself. ^_^

    This very simple snippet I was made for my own convenience, so if you go to
    http://nimja.com/random
    The page doesn’t exist, go to the 404 and it does a search for you. Let’s get on with it.

    Snippet: (put this in a snippet called: SetSearch)
    <?php
    /* SetSaerch snippet.
     * Usage: simply place this code in a snippet and use it on the 404 page:
     * [!SetSaerch!]
     * [!AjaxSearch? &AS_showForm=`0` &ajaxSearch=`0`!]
     * NOTE: An AjaxSearch call NEEDS to be included after this call for this to have any effect.
     */
    
    if (!empty($_GET['q']) && empty($_GET['AS_search'])){
    	//Strip slashes and dashes to spaces and do an URL decode to clean up the query.
        $cleanQuery = strtr(urldecode($_GET['q']),"/-","  ");
    
    	//Remove any words consisting of only 1 or 2 letters  due to AjaxSearch's limit
    	$cleanQuery = preg_replace('/\b\w{1,2}\b/','',$cleanQuery);
    
    	//Find position of last . (in case of multiple .'s)
        $dotPos = strrpos($ssStrQuery,".");  
    
    	//If there is a . involved (so a possible extentsion)
        if ($dotPos !== false){
        	//Remove everything after (and including) the last .
            $cleanQuery = substr($cleanQuery,0,$dotPos);
        }
    
    	//Set the POST value that AjasSearch uses.
        $_POST['search'] = $cleanQuery;
    }
    //Return empty handed (post contains search value)
    return null;
    ?>


    The page code: (put this on the page you want to use it on, and have the configuration set to use this as the 404 page.
    [!SetSearch!]
    [!AjaxSearch? &AS_showForm=`0` &ajaxSearch=`0`!]


    The result:

    On your 404 page you actually get dynamic search results using the standard AjaxSearch that just make your site look incredibly nifty. And it only takes 1 minute to install. What more could you want?

    Also, it supports multiple result pages. (quick fix 2 minutes ago)
    Can easily be adjusted for many other scenario’s as well.

    ps. It could be made a whole lot better, supporting chunks and all kinds of different things. This is just a very simple example of how to use URL rewriting into a dynamic page.

    pps. Updated with the short word fix.
      [font=Times]Comics, stories, music, graphics, games and more! http://Nimja.com
      • 10487 MODX Staff
      • 1,535 Posts
      Simple but brilliant! grin That’s going to be implemented on my sites very shortly.
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 25663 MODX Staff
        • 12,272 Posts
        Now that is really cool indeed. Nicely done. smiley
          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
          • 14050
          • 788 Posts
          Thank you. I just added it to my site!
            Jesse R.
            Consider trying something new and extraordinary.
            Illinois Wine

            Have you considered donating to MODx lately?
            Donate now. Every contribution helps.
            • 21560
            • 145 Posts
            So far no issues have been found. So, goody!
              [font=Times]Comics, stories, music, graphics, games and more! http://Nimja.com
              • 7231
              • 4,205 Posts
              I just love when I see thinking outside of the box, taking everyday tools (if you can call AjaxSearch an everyday tool grin ) and making something simple yet very cool. Thanks for sharing this cool idea, I may just need to use it sometime.
                [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                Something is happening here, but you don&#39;t know what it is.
                Do you, Mr. Jones? - [bob dylan]
                • 21560
                • 145 Posts
                Well it was only a matter of time. I mean... www.php.net has it. ^_^

                If THE most important site of the internet has it, why not MODx? And it’s basically tying one end to the other wink

                It’s all there, just ... not connected.
                  [font=Times]Comics, stories, music, graphics, games and more! http://Nimja.com
                  • 6726
                  • 7,075 Posts
                  Yeah I have seen this kind of feature and wanted to have it, that’s great !
                  Thanks smiley)
                    .: COO - Commerce Guys - Community Driven Innovation :.


                    MODx est l&#39;outil id
                    • 21560
                    • 145 Posts
                    Only serving the community wink
                      [font=Times]Comics, stories, music, graphics, games and more! http://Nimja.com
                      • 33337
                      • 3,975 Posts
                      The great little useful snippet!

                      I appreciate your efforts man! smiley

                      regards.
                        Zaigham R - MODX Professional | Skype | Email | Twitter

                        Digging the interwebs for #MODX gems and bringing it to you. modx.link