Google 即搜即得如何运作?
关于新的谷歌即时搜索到底如何工作有什么想法吗?这似乎只是对旧搜索的 AJAX 调用,但要简化 Google 是相当困难的。有人有猜测吗?
编辑: 我知道每次按键都会发送 AJAX,但它是否具有预测性?或者您认为这只是常规的谷歌搜索?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
更新:Google 刚刚发布了一篇名为 Google 即搜即得,幕后黑手。这是一本有趣的读物,显然与这个问题相关。例如,您可以阅读他们如何解决服务器端的额外负载(根据文章,为 5-7 倍)。下面的答案检查了客户端发生的情况:
通过 Firebug 检查,Google 正在做一个 Ajax 每次按键时的 GET 请求:
我想它的工作方式与自动完成相同。不过这一次,它还以 JSON 格式返回部分完整搜索短语的搜索结果。
输入“Stack Overflow”时检查 JSON 响应之一:
我们可以看到 JSON 响应包含内容在我们键入时构建搜索结果。
格式化的 JSON 响应如下所示:
进一步的非技术性阅读:
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:
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":
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:
Further non-technical reading:
正如其他人所说,Google 会立即返回 Google Suggest 建议的最佳结果。因此,如果您输入 fac,Google 建议会认为您输入的是 facebook。有趣的是,只有部分搜索词 fac 在 JSON 请求中发送到 Google,因此两端都使用 Google Suggest。
实际上,并不是每次击键都会执行搜索。如果您打字速度足够快,有些内容可能会被错过。
我怀疑这不会像你想象的那样增加谷歌服务器的负载。当您开始输入内容时,大多数附加搜索都是针对非常流行的单词 - 如果您开始搜索以 f 开头的内容,它会搜索 facebook,如果您开始搜索以 ju 开头的内容,它将搜索 justin bieber。由于缓存,这些搜索的成本并不是很高。
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.
这是有预测性的。搜索结果来自第一个自动完成建议(如果您点击向下箭头或将鼠标悬停在建议上,则来自选定的建议)。
换句话说,如果我输入“vinyl s”,第一个自动完成建议是“vinyl siding”,并且搜索结果清楚地显示对“vinyl siding”的搜索。如果我用普通的谷歌搜索“vinyl s”,搜索结果会有所不同。
因此,谷歌即时搜索具有预测性,而普通谷歌搜索则不然……它搜索建议的自动完成,而不是字面未完成的搜索查询。
It's predictive. The search results are from the first autocomplete suggestion (or the selected one if you hit the down arrow or mouse over a suggestion).
In other words if I type "vinyl s", the first autocomplete suggestion is "vinyl siding," and the search results clearly show a search for "vinyl siding." If I do a normal google search for "vinyl s," the search results are different.
So google instant is predictive in a way that normal google searches are not... it searches for the suggested autocompletion instead of the literal unfinished search query.
在 Daniel Vassallo 的答案的 Ajax 响应中转换键
u
的第一个值会给出 URL,然后得到一些(无效的)JSON。我还不确定这一点是做什么用的。d
提供一些 HTML,将其插入到页面中。这是一个稍微解压版本。它主要是一个脚本标签,它将另外 2 个 HTML 块 传递给函数je.pa( )
。这些块似乎与非即时搜索结果相同。Converting the first value from key
u
in Daniel Vassallo's answer's Ajax response gives a URL, which then leads to some (invalid) JSON. I'm not sure what this bit is for yet.The
d
gives some HTML, which gets inserted into the page. Here's a slightly decompressed version. It's mostly a script tag, which passes in 2 further chunks of HTML to a functionje.pa()
. These chunks seem to be the same as the non-instant search results.我不久前为 Solr 搜索引擎编写了一个不太流行的即时搜索 GUI。它非常简单,因此您应该能够查看代码并理解一般概念 http://fergiemcdowall.github .io/solrstrap/
I while ago I wrote a vaguely popular instant search GUI for the Solr search engine. Its really simple, so you should be able to look at the code and understand the general concepts http://fergiemcdowall.github.io/solrstrap/