This topic is locked

Google style Instant Search feature (using ajax suggest)

10/27/2011 11:47:38 AM
PHPRunner Tips and Tricks
F
FunkDaddy author

PHP Runner has the great ajax search suggest feature. The only thing it lacks is the ability to instantly perform the search as soon as you select one of the suggested options that appear below the search box. Currently you hav to select an option, then manually click/submit the search for it to take place.
If you are interested in having your searches perform like the "Google Instant" feature, here's how you do it.

  1. Find the "ajaxsuggest.js" file in your "include" folder wherever your app folder is output.
  2. Add the following line of code to the end of the setSearch function (inside that function of course):



runLoading(1,getParentTableObj(1),4); searchController1.submitSearch();


3. That's it. So the setSearch function should now look like this:



function setSearch(inputName,value){

if(setSearch.arguments[2]=='lookup'){isLookupError=false;var helement=$("#"+inputName.substring(8)+setSearch.arguments[4])[0];$("#"+inputName+setSearch.arguments[4]).removeClass("highlight");$("#"+inputName+setSearch.arguments[4]).val(value);if($(helement).val()!=setSearch.arguments[3])

{$(helement).val(setSearch.arguments[3]);$(helement).change();}}

else

$("input[@type=text][@name="+inputName+"]").val(value);DestroySuggestDiv();

runLoading(1,getParentTableObj(1),4); searchController1.submitSearch();

}
P
Pierre DAC 11/17/2011

Thank you but I cant make it work in last v6 of phprunner.

O
Osric44 12/7/2011

As others have said, Google is instantly returning the results for the top result of what Google Suggest suggests. Therefore, if you type in fac, Google Suggests thinks you are typing in facebook. Interestingly, only the partial search term, fac, is sent to Google in the JSON request, so Google Suggest is used at both ends.
Searches are not actually performed on every keystroke. If you type fast enough, some can get missed.
I suspect this doesn't increase the load on Google's servers as much as you might think. Most of the additional searches are for very popular words when you start typing stuff in - if you starting searching for something beginning with f, it will search for facebook, if you start searching for something beginning with ju, it will search for justin bieber. Thanks to caching, these searches are not very expensive to do.