Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

ajax - How does Google Instant work?

Any ideas on exactly how the new google instant search works? It seems to just be AJAX calls to the old search, but it's pretty hard to simplify Google that much. Anybody have speculations?

EDIT: I know there is AJAX sent with each keypress, but is it predictive? Or do you think it's just a regular ol' google search?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

UPDATE: Google have just published a blog article called Google Instant, behind the scenes. It's an interesting read, and obviously related to this question. You can read how they tackled the extra load (5-7X according to the article) on the server-side, for example. The answer below examines what happens on the client-side:


Examining with Firebug, Google is doing an Ajax GET request on every keypress:

Google Instant Search

I guess it's working the same way as the auto completion. However this time, it also returns the search results of the partially complete search phrase in JSON format.

Examining one of the JSON responses while typing "Stack Overflow":

Google Instant Search Ponies

We can see that the JSON response contains the content to construct the search results as we type.

The formatted JSON responses look something like this:

{
    e: "j9iHTLXlLNmXOJLQ3cMO",
    c: 1,
    u: "http://www.google.com/search?hlx3denx26expIdsx3d17259,24472,24923,25260,25901,25907,26095,26446,26530x26sugexpx3dldymlsx26xhrx3dtx26qx3dStack%20Overflowx26cpx3d6x26pfx3dpx26sclientx3dpsyx26aqx3dfx26aqix3dg4g-o1x26aqlx3dx26oqx3dStack+x26gs_rfaix3dx26pbxx3d1x26fpx3df97fdf10596ae095x26tchx3d1x26echx3d1x26psix3dj9iHTO3xBo2CONvDzaEO12839712156911",
    d: "x3clink relx3dprefetch hrefx3dx22http://stackoverflow.com/x22x3ex3cscriptx3eje.pa(_loc, x27rsox27, x27\x3c!--m--\x3e\x3clink rel\x3dprefetch href\x3d\x22http://stackoverflow.com/\x22\x3e\x3cli class\x3dg\x3e\x3ch3 class\x3d\x22r\x22\x3e\x3ca href\x3d\x22http://stackoverflow.com/\x22 class\x3dl onmousedown\x3d\x22return rwt(this,\x27\x27,\x27\x27,\x27\x27,\x271\x27,\x27AFQjCNERidL9Hb6OvGW93_Y6MRj3aTdMVA\x27,\x27\x27,\x270CBYQFjAA\x27)\x22\x3e\x3cem\x3eStack Overflow\x3c/em\x3e\x3c/a\x3e\x3c/h3\x3e\x3cdiv class\x3d\x22s\x22\x3eA language-independent collaboratively edited question and answer site for programmers.\x3cbr\x3e\x3cspan class\x3df\x3e\x3ccite\x3e\x3cb\x3estackoverflow\x3c/b\x3e.com/\x3c/cite\x3e - \x3cspan class\x3dgl\x3e\x3ca href\x3d\x22http://webcache.googleusercontent.com/search?q\x3dcache:U1GC2GYOToIJ:stackoverflow.com/+Stack+Overflow\x26amp;cd\x3d1\x26amp;hl\x3den\x26amp;ct\x3dclnk\x22 onmousedown\x3d\x22return rwt(this,\x27\x27,\x27\x27,\x27\x27,\x271\x27,\x27AFQjCNFfKMag7Tq8CMbbfu8Gcj_GjukTbA\x27,\x27\x27,\x270CBgQIDAA\x27)\x22\x3eCached\x3c/a\x3e - \x3ca href\x3d\x22/search?hl\x3den\x26amp;q\x3drelated:stackoverflow.com/+Stack+Overflow\x26amp;tbo\x3d1\x26amp;sa\x3dX\x26amp;ei\x3dj9iHTLXlLNmXOJLQ3cMO\x26amp;sqi\x3d2\x26amp;ved\x3d0CBkQHzAA\x22\x3eSimilar\x3c/a\x3e\x3c/span\x3e\x3c/span\x3e\x3cbr\x3e\x3ctable class\x3dslk style\x3d\x22border-collapse:collapse;margin-top:4px\x22\x3e\x3ctr\x3e\x3ctd style\x3d\x22padding-left:14px;vertical-align:top\x22\x3e\x3cdiv class\x3dsld\x3e\x3ca class\x3dsla href\x3d\x22http://stackoverflow.com/questions\x22 onmousedown\x3d\x22return rwt(this,\x27\x27,\x27\x27,\x27\x27,\x271\x27,\x27AFQjCNHmP78gEctJKvBrydP2c52F_FEjvA\x27,\x27\x27,\x270CBoQqwMoADAA\x27)\x22\x3eQuestions\x3c/a\x3e\x3c/div\x3e\x3cdiv class\x3dsld\x3e\x3ca class\x3dsla href\x3d\x22http://stackoverflow.com/questions/ask\x22 onmousedown\x3d\x22return rwt(this,\x27\x27,\x27\x27,\x27\x27,\x271\x27,\x27AFQjCNGZF-qwWVTZOWPlr4vgSA7qB64LLQ\x27,\x27\x27,\x270CBsQqwMoATAA\x27)\x22\x3eAsk Question\x3c/a\x3e\x3c/div\x3e\x3cdiv class\x3dsld\x3e\x3ca class\x3dsla href\x3d\x22http://stackoverflow.com/users/135152/omg-ponies\x22 onmousedown\x3d\x22return rwt(this,\x27\x27,\x27\x27,\x27\x27,\x271\x27,\x27AFQjCNE9zo6Qi_AM1bjmPGeMGfbnPi3niA\x27,\x27\x27,\x270CBwQqwMoAjAA\x27)\x22\x3eOMG Ponies\x3c/a\x3e\x3c/div\x3e\x3cdiv class\x3dsld\x3e\x3ca class\x3dsla href\x3d\x22http://careers.stackoverflow.com/\x22 onmousedown\x3d\x22return rwt(this,\x27\x27,\x27\x27,\x27\x27,\x271\x27,\x27AFQjCNEaqlBrfDcc1gdPZ6dgthff0s5WmA\x27,\x27\x27,\x270CB0QqwMoAzAA\x27)\x22\x3eCareers\x3c/a\x3e\x3c/div\x3e\x3ctd style\x3d\x22padding-left:14px;vertical-align:top\x22\x3e\x3cdiv class\x3dsld\x3e\x3ca class\x3dsla href\x3d\x22http://stackoverflow.com/about\x22 onmousedown\x3d\x22return rwt(this,\x27\x27,\x27\x27,\x27\x27,\x271\x27,\x27AFQjCNEqgPttrXj3r4o3TZHX5WaWvFe1HQ\x27,\x27\x27,\x270CB4QqwMoBDAA\x27)\x22\x3eAbout\x3c/a\x3e\x3c/div\x3e\x3cdiv class\x3dsld\x3e\x3ca class\x3dsla href\x3d\x22http://stackoverflow.com/faq\x22 onmousedown\x3d\x22return rwt(this,\x27\x27,\x27\x27,\x27\x27,\x271\x27,\x27AFQjCNF3X3eRc0RsxYynXZhhbyYkuKWZ5g\x27,\x27\x27,\x270CB8QqwMoBTAA\x27)\x22\x3eThe FAQ\x3c/a\x3e\x3c/div\x3e\x3cdiv class\x3dsld\x3e\x3ca class\x3dsla href\x3d\x22http://blog.stackoverflow.com/\x22 onmousedown\x3d\x22return rwt(this,\x27\x27,\x27\x27,\x27\x27,\x271\x27,\x27AFQjCNG7KphjK6RuC5cj-6U5jeuvipt5dg\x27,\x27\x27,\x270CCAQqwMoBjAA\x27)\x22\x3eBlog\x3c/a\x3e\x3c/div\x3e\x3cdiv class\x3dsld\x3e\x3ca class\x3dsla href\x3d\x22http://stackoverflow.com/users\x22 onmousedown\x3d\x22return rwt(this,\x27\x27,\x27\x27,\x27\x27,\x271\x27,\x27AFQjCNFfN_wcGm4HE5XpDxvcH4bIrkv2dw\x27,\x27\x27,\x270CCEQqwMoBzAA\x27)\x22\x3eUsers\x3c/a\x3e\x3c/div\x3e\x3ctr\x3e\x3ctd colspan\x3d2 style\x3d\x22padding-left:14px;vertical-align:top\x22\x3e\x3cdiv style\x3d\x22padding-top:6px\x22\x3e\x3ca class\x3dfl href\x3d\x22/search?hl\x3den\x26amp;q\x3d+site:stackoverflow.com+Stack+Overflow\x26amp;sa\x3dX\x26amp;ei\x3dj9iHTLXlLNmXOJLQ3cMO\x26amp;sqi\x3d2\x26amp;ved\x3d0CCIQrAM\x22\x3eMore results from stackoverflow.com\x26nbsp;\x26raquo;\x3c/a\x3e\x3c/div\x3e\x3c/table\x3e\x3c/div\x3e\x3c!--n--\x3e\x3c!--m--\x3e\x3cli class\x3dg\x3e\x3ch3 class\x3d\x22r\x22\x3e\x3ca href\x3d\x22http://stackoverflow.com/questions\x22 class\x3dl onmousedown\x3d\x22return rwt(this,\x27\x27,\x27\x27,\x27\x27,\x272\x27,\x27AFQjCNHmP78gEctJKvBrydP2c52F_FEjvA\x27,\x27\x27,\x270CCUQFjAB\x27)\x22\x3eHottest Questions - \x3cem\x3eStack Overflow\x3c/em\x3e\x3c/a\x3e\x3c/h3\x3e\x3cdiv class\x3d\x22s\x22\x3eHello \x3cem\x3eStack Overflow\x3c/em\x3e! I\x26#39;m working with someone else\x26#39;s PHP function that works fine as long as I pass it at least three arguments. If I pass it two argument, \x3cb\x3e...\x3c/b\x3e\x3cbr\x3e\x3cspan class\x3df\x3e\x3ccite\x3e\x3cb\x3estackoverflow\x3c/b\x3e.com/questions\x3c/cite\x3e - \x3cspan class\x3dgl\x3e\x3ca href\x3d\x22http://webcache.googleusercontent.com/search?q\x3dcache:6S_0sErDKfQJ:stackoverflow.com/questions+Stack+Overflow\x26amp;cd\x3d2\x26amp;hl\x3den\x26amp;ct\x3dclnk\x22 onmousedown\x3d\x22return rwt(this,\x27\x27,\x27\x27,\x27\x27,\x272\x27,\x27AFQjCNH7WHzefYlnS05ln4j6rzfE3byDKg\x27,\x27\x27,\x270CCcQIDAB\x27)\x22\x3eCached\x3c/a\x3e - \x3ca href\x3d\x22/search?hl\x3den\x26amp;q\x3drelated:stackoverflow.com/questions+Stack+Overflow\x26amp;tbo\x3d1\x26amp;sa\x3dX\x26amp;ei\x3dj9iHTLXlLNmXOJLQ3cMO\x26amp;sqi\x3d2\x26amp;ved\x3d0CCgQHzAB\x22\x3eSimilar\x3c/a\x3e\x3c/span\x3e\x3c/span\x3e\x3c/div\x3e\x3c!--n--\x3e\x3c!--m--\x3e\x3cli class\x3dg\x3e\x3ch3 class\x3d\x22r\x22\x3e\x3ca href\x3d\x22http://en.wikipedia.org/wiki/Stack_overflow\x22 class\x3dl onmousedown\x3d\x22return rwt(this,\x27\x27,\x27\x27,\x27\x27,\x273\x27,\x27AFQjCNEAxaeWmWtD7cBcmZ5QBMsTRNbnCw\x27,\x27\x27,\x270CCkQFjAC\x27)\x22\x3e\x3cem\x3eStack overflow\x3c/em\x3e - Wikipedia, the free encyclopedia\x3c/a\x3e\x3c/h3\x3e\x3cdiv class\x3d\x22s\x22\x3eIn software, a \x3cem\x3estack overflow\x3c/em\x3e occurs when too much memory is used on the call stack. The call stack contains a limited amount of memory,  often determined at \x3cb\x3e...\x3c/b\x3e\x3cbr\x3e\x3cspan class\x3df\x3e\x3ccite\x3een.wikipedia.org/wiki/\x3cb\x3eStack\x3c/b\x3e_\x3cb\x3eoverflow\x3c/b\x3e\x3c/cite\x3e - \x3cspan class\x3dgl\x3e\x3ca href\x3d\x22http://webcache.googleusercontent.com/search?q\x3dcache:mWu8b0BQAmwJ:en.wikipedia.org/wiki/Stack_overflow+Stack+Overflow\x26amp;cd\x3d3\x26amp;hl\x3den\x26amp;ct\x3dclnk\x22 onmousedown\x3d\x22return rwt(this,\x27\x27,\x27\x27,\x27\x27,\x273\x27,\x27AFQjCNFG_5ndK-KmWJy6s3pOsi8lsxqEZg\x27,\x27\x27,\x270CCsQIDAC\x27)\x22\x3eCached\x3c/a\x3e - \x3ca href\x3d\x22/search?hl\x3den\x26amp;q\x3drelated:en.wikipedia.org/wiki/Stack_overflow+Stack+Overflow\x26amp;tbo\x3d1\x26amp;sa\x3dX\x26amp;ei\x3dj9iHTLXlLNmXOJLQ3cMO\x26amp;sqi\x3d2\x26amp;ved\x3d0CCwQHzAC\x22\x3eSimilar\x3c/a\x3e\x3c/span\x3e\x3c/span\x3e\x3c/div\x3e\x3c!--n--\x3e\x3c!--m--\x3e\x3cli class\x3dg\x3e\x3ch3 class\x3d\x22r\x22\x3e\x3ca href\x3d\x22http://blog.stackoverflow.com/\x22 class\x3dl onmousedown\x3d\x22return rwt(this,\x27\x27,\x27\x27,\x27\x27,\x274\x27,\x27AFQjCNG7KphjK6RuC5cj-6U5jeuvipt5dg\x27,\x27\x27,\x270CC0QFjAD\x27)\x22\x3eBlog – \x3cem\x3eStack Overflow\x3c/em\x3e\x3c/a\x3e\x3c/h3\x3e\x3cdiv class\x3d\x22s\x22\x3e6 Sep 2010 \x3cb\x3e...\x3c/b\x3e The latest version of the \x3cem\x3eStack Overflow\x3c/em\x3e Trilogy Creative Commons Data Dump is now available. This reflects all public  data in … \x3cb\x3e...\x3c/b\x3e\x3cbr\x3e\x3cspan class\x3df\x3e\x3ccite\x3eblog.\x3cb\x3estackoverflow\x3c/b\x3e.com/\x3c/cite\x3e - \x3cspan class\x3dgl\x3e\x3ca href\x3d\x22http://webcache.googleusercontent.com/search?q\x3dcache:iqtvg9Ge1c0J:blog.stackoverflow.com/+Stack+Overflow\x26amp;cd\x3d4\x26amp;hl\x3den\x26amp;ct\x3dclnk\x22 onmousedown\x3d\x22return rwt(this,\x27\x27,\x27\x27,\x27\x27,\x274\x27,\x27AFQjCNFX2P2-RTCs_GaR6NgSw30p007UEA\x27,\x27\x27,\x270CC8QIDAD\x27)\x22\x3eCached\x3c/a\x3e - \x3ca href\x3d\x22/search?hl\x3den\x26amp;q\x3drelated:blog.stackoverflow.com/+Stack+Overflow\x26amp;tbo\x3d1\x26amp;sa\x3dX\x26amp;ei\x3dj9iHTLXlLNmXOJLQ3cMO\x26amp;sqi\x3d2\x26amp;ved\x3d0CDAQHzAD\x22\x3eSimilar\x3c/a\x3e\x3c/span\x3e\x3c/span\x3e\x3c/div\x3e\x3c!--n--\x3ex27,_ss);x3c/scriptx3e"
}/*""*/{
    e: "j9iHTLXlLNmXOJLQ3cMO",
    c: 1,
    u: "http://www.google.com/search?hlx3denx26expIdsx3d17259,24472,24923,25260,25901,25907,26095,26446,26530x26sugexpx3dldymlsx26xhrx3dtx26qx3dStack%20Overflowx26cpx3d6x26pfx3dpx26sclientx3dpsyx26aqx3dfx26aqix3dg4g-o1x26aqlx3dx26oqx3dStack+x26gs_rfaix3dx26pbxx3d1x26fpx3df97fdf10596ae095x26tchx3d1x26echx3d1x26psix3dj9iHTO3xBo2CONvDzaEO12839712156911",
    d: "x3cscriptx3eje.pa(_loc, x27rsox27, x27\x3c!--m--\x3e\x3cli class\x3dg style\x3d\x22margin-left:16px\x22\x3e\x3ch3 class\x3d\x22r hcw\x22\x3e\x3ca href\x3d\x22http://blog.stackoverflow.com/category/podcasts/\x22 class\x3dl onmousedown\x3d\x22return rwt(this,\x27\x27,\x27\x27,\x27\x27,\x275\x27,\x27AFQjCNGnAJSxUa4GLcg-E7PNvIFmPC53gQ\x27,\x27\x27,\x270CDEQFjAE\x27)\x22\x3epodcasts - Blog – \x3cem\x3eStack Overflow\x3c/em\x3e\x3c/a\x3e\x3c/h3\x3e\x3cdiv class\x3d\x22s hc\x22\x3eJoel and Jeff sit down with our new community coordinator, Robert Cartaino, to record a “bonus” podcast discussing the future of \x3cem\x3eStack Overflow\x3c/em\x3e and Stack \x3cb\x3e...\x3c/b\x3e\x3cbr\x3e\x3cspan class\x3df\x3e\x3ccite\x3eblog.\x3cb\x3estackoverflow\x3c/b\x3e.com/category/podcasts/\x3c/cite\x3e - \x3cspan class\x3dgl\x3e\x3ca href\x3d\x22http://webcache.googleusercontent.com/search?q\x3dcache:JT0sWmmtiAEJ:blog.stackoverflow.com/category/podcasts/+Stack+Overflow\x26amp;cd\x3d5\x26amp;hl\x3den\x26amp;ct\x3dclnk\x22 onmousedown\x3d\x22return rwt(this,\x27\x27,\x27\x27,\x27\x27,\x275\x27,\x27AFQjCNErCiLBch55HA8i5BAdChcmQYH8nw\x27,\x27\x27,\x270CDMQIDAE\x27)\x22\x3eCached\x3c/a\x3e - \x3ca href\x3d\x22/search?hl\x3den\x26amp;q\x3drelated:blog.stackoverflow.com/category/podcasts/+Stack+Overflow\x26amp;tbo\x3d1\x26amp;sa\x3dX\x26amp;ei\x3dj9iHTLXlLNmXOJLQ3cMO\x26amp;sqi\x3d2\x26amp;ved\x3d0CDQQHzAE\x22\x3eSimilar\x3c/a\x3e\x3c/span\x3e\x3c/s

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...