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

    So I am using the SimpleSearch add on to search through my website but I am also using jquery autocomplete with a snippet that I wrote that just gets the pagetitles of resources under a certain parent and shows them in a drop down below the search bar.

    People might want to search for something not in the parent category that I have specified so I would still like to keep a general search throughout the whole site but at the moment if someone selects one of the options from the dropdown it goes to the search results page with only that option as a result because it is an exact match for the pagetitle.

    I was wondering if there is a way to make SimpleSearch go directly to the resource if the search is exactly the same as the pagetitle and there is only one result instead of taking the user to the results page and then having to click again on the single result to get to where they are trying to go.

    SimpleSearch modx Docs page: http://rtfm.modx.com/extras/revo/simplesearch

    Thanks

    Matt
      • 42562
      • 1,145 Posts
      Will client-side code work for you?
      Search is made, page loads, JS sees a match, and redirects.
      To avoid mayhem, set SimpleSearch to be strict, whole sentence search, so that you don't have multiple entries
      $(".resultPageTitleLink").each(function(){
      if($(this).text() == $("#searchField").val())
      //alert($(this).text());//for debug
      window.location.replace(this.href);
      })
      
        TinymceWrapper: Complete back/frontend content solution.
        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
        • 42596
        • 45 Posts
        Thanks for this...but if my understanding is correct then this code would only execute on the results page anyway? I am looking to skip that altogether as the user might find this somewhat confusing? Or would if just be a flash of the page? If nothing better comes up through here then I will implement this.

        Thanks again!
          • 4172
          • 5,888 Posts
          you could create a snippet like that:

          <?php
          
          $search = $modx->getOption('search',$_REQUEST,'');
          
          if (!empty($search) && $object = $modx->getObject('modResource',array('published'=>'1','deleted'=>'0','pagetitle'=>$search))){
              $url = $modx->makeUrl($object->get('id'));
              $modx->sendRedirect($url);
          }


          and call it at the top of your search-landing-page.
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 42562
            • 1,145 Posts
            Quote from: Bruno17 at Jul 15, 2015, 11:44 AM
            you could create a snippet like that...
            There is code, and then there is magic!!!

            This looks awesome.
              TinymceWrapper: Complete back/frontend content solution.
              Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
              5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
              • 3749
              • 24,544 Posts
              Cool idea, and an excellent example of what makes MODX so great. wink
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting