We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21560
    • 145 Posts
    Theoretically you’d want this in the ajax-search snippet anyway. ^_^

    "If requested page is different from current alias, display search results."

    Would be more solid then a seperate snippet. But this works too I suppose.

    That reminds me, I did find a bug. A small one that is slightly irrelevant.

    A search will still happen if the document is requested with it’s proper alias. (’nowhere’ in my case) This is both good and bad. I consider it too good to be bothered about the bad.
      [font=Times]Comics, stories, music, graphics, games and more! http://Nimja.com
      • 9941
      • 65 Posts
      You should look into exploding the search string (after domain name) on the / and using each part as a keyword... also strip out the suffix (.html or whatever) as that is almost always going to return no results ie: http://nimja.com/random.html give you no results.

      This would all need to happen after it’s been determined that it’s a 404 response of course (but I think your snippet only runs after that correct? as it’s inline in the 404 document).

      Great snippet btw... just mentioning a few thoughts.




        • 21560
        • 145 Posts
        All good suggestions. I’ll see if I can put them in. Just removing a suffix if it’s set in MODX. Also I wonder if I can let MODx strip it itself. I’m lazy like that wink

        Anyway, thanks for the feedback!
          [font=Times]Comics, stories, music, graphics, games and more! http://Nimja.com
          • 9941
          • 65 Posts
          I just like exploding things! Glad to be of service... this is something I’ve been wanting to do myself for a while actually ;-p great minds think a like... errr something like that ;-p
            • 16534
            • 47 Posts
            How would I change the colour of "Searching..."?

            I used a span around the [
            ] itself, but that didn't work. I wrapped the span around the <h2>Searching...</h2> part in the snippet as well but then I ended up with getting no search results.
              • 21560
              • 145 Posts
              It’s automatically styled in a <h2> object. Of course you can simply make it any class, thing you want.

              It’s basic CSS styling, but I didn’t include a seperate ID/Class. Probably lazyness on my part. ^_^
                [font=Times]Comics, stories, music, graphics, games and more! http://Nimja.com
                • 13902
                • 5 Posts
                Quote from: foniksonik at Oct 31, 2007, 03:09 PM

                You should look into exploding the search string (after domain name) on the / and using each part as a keyword... also strip out the suffix (.html or whatever) as that is almost always going to return no results ie: http://nimja.com/random.html give you no results.

                Hi all,

                Although I’m no PHP coder, i took a crack at this:

                <?php
                //Very VERY simple call to set the right POST value for AjaxSearch.
                if (!empty($_GET['q']) && empty($_GET['AS_search'])){
                    $ssStrQuery = strtr(urldecode($_GET['q']),"/-","  "); // translate address to search string (slashes and dashes to spaces)
                    $ssNrPos = strpos($ssStrQuery,"."); // is there an extension(.html, .php)?
                    if ($ssNrPos !== false){
                        $ssStrQuery = substr($ssStrQuery,0,$ssNrPos); // if there is, strip it.
                    }
                    unset($ssNrPos); // the wiki advises to free memory, don't know if it's needed.
                    $_POST['search'] = $ssStrQuery;
                    unset($ssStrQuery);
                    return;
                } else {
                    return null;
                }
                ?>
                


                On my local dev server it’s working fine.
                  • 9941
                  • 65 Posts
                  What’s great about a snippet like this is that you can use a custom AjaxSearch template to create a "Related Pages" block on a page.... especially if you were to also grab the current pages keywords TV and add it in to the mix, then in your template just show the linked pagetitles of the search results ;-p

                  No example yet, just thought of it while re-reading this thread....
                    • 21560
                    • 145 Posts
                    Very nice jeffkono.

                    I don’t use extensions on my page, but it’s a good idea to strip them. I’ll look into this one some time again. I haven’t touched it for a while. PDF’s taking my attention wink
                      [font=Times]Comics, stories, music, graphics, games and more! http://Nimja.com
                      • 13902
                      • 5 Posts
                      Quote from: Nimja at Feb 11, 2008, 09:58 AM

                      I haven’t touched it for a while. PDF’s taking my attention wink

                      You mean this one?

                      Ooooh, dynamic PDFs! Nice! wink