Google Suggest
What is that??? chk out here
As you type into the search box, Google Suggest guesses what you're typing and offers suggestions in real time. This is similar to Google's "Did you mean?" feature that offers alternative spellings for your query after you search, except that it works in real time. For example, if you type "bass," Google Suggest might offer a list of refinements that include "bass fishing" or "bass guitar." Similarly, if you type in only part of a word, like "progr," Google Suggest might offer you refinements like "programming," "programming languages," "progesterone," or "progressive." You can choose one by scrolling up or down the list with the arrow keys or mouse.
This uses a wide range of information to predict the queries users are most likely to want to see. For example, Google Suggest uses data about the overall popularity of various searches to help rank the refinements it offers. An example of this type of popularity information can be found in the Google Zeitgeist.
For people who want to see how this works check out the google javascript code
This code at very first instance looks cryptic since the function and variable name are coded. Some real good guys have decoded this code to a presentable form check out this . The code looks simplified with proper comments inplace.
The magic lies here..
function callGoogle(Rb){
if(_xmlHttp&&_xmlHttp.readyState!=0){
_xmlHttp.abort()
}
_xmlHttp=getXMLHTTP();
if(_xmlHttp){
// We end up calling:
// /complete/search?hl=en&js=true&qu= ...
_xmlHttp.open("GET",_completeSearchEnString+"&js=true&qu="+Rb,true);
// Note that this function will ONLY be called when we get a complete
// response back from google!!
_xmlHttp.onreadystatechange=function() {
if(_xmlHttp.readyState==4&&_xmlHttp.responseText) {
var frameElement=B;
if(_xmlHttp.responseText.charAt(0)=="<"){
_timeoutAdjustment--
}else{
// The response text gets executed as javascript...
eval(_xmlHttp.responseText)
}
}
} ;
// DON'T TRY TO TALK WHEN WE'RE LOCAL...
// Comment out when running from a local file...
_xmlHttp.send(null)
}
}
On key hit event a XMLHTTP object is sent to google, queried and results
back to page where it orginate.
General methodology to communicate with server without realoading the page( as on orkut's rating page where you click a particular image and a request to server is posted without effecting the original page ) is embedding a hidden iframe element. When a query needs to be posted the page in the iframe element is called that does processing on server and the results are returned to the parent page( that include the iframe) by calling its javascript function that handles request and reflect it on the parent page. Did you realise this is what is known as remote procedure calls ?? :D Without any addons you deviced a method of remote procedures. It looks good and simple. May be i'll put some working demo here in future.
0 Comments:
Post a Comment
<< Home