<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>shazow.net &#187; appengine</title>
	<atom:link href="http://shazow.net/blog/tag/appengine/feed/" rel="self" type="application/rss+xml" />
	<link>http://shazow.net/blog</link>
	<description>The cake is a lie</description>
	<lastBuildDate>Sun, 23 May 2010 22:13:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Google&#8217;s Lucky is fickle, too</title>
		<link>http://shazow.net/blog/2008/10/16/googles-lucky-is-fickle-too/</link>
		<comments>http://shazow.net/blog/2008/10/16/googles-lucky-is-fickle-too/#comments</comments>
		<pubDate>Thu, 16 Oct 2008 05:01:04 +0000</pubDate>
		<dc:creator>shazow</dc:creator>
				<category><![CDATA[Rants]]></category>
		<category><![CDATA[appengine]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://shazow.net/blog/?p=132</guid>
		<description><![CDATA[
One of Google&#8217;s most used underacknowledged features is the I&#8217;m Feeling Lucky query. On the surface, it seems silly and beside the point, but many people have grown to depend on it. What is it good for? Link resolving. You could go to Youtube.com and type &#8220;Rickroll&#8221; into the search box, or you could type [...]]]></description>
			<content:encoded><![CDATA[<p>
One of Google&#8217;s most used underacknowledged features is the <em>I&#8217;m Feeling Lucky</em> query. On the surface, it seems silly and beside the point, but many people have grown to depend on it. What is it good for? Link resolving. You could go to Youtube.com and type &#8220;Rickroll&#8221; into the search box, or you could type &#8220;<a href="http://www.google.ca/search?q=rickroll+video&#038;btnI=1">rickroll video</a>&#8221; into your Firefox address bar (effectively doing an I&#8217;m Feeling Lucky search) and jump straight to where you want to go.
</p>
<p>
I no longer type &#8220;wikipedia.org&#8221; when I can type &#8220;<a href="http://www.google.ca/search?q=wikipedia&#038;btnI=1">wikipedia</a>&#8220;. Why type &#8220;mail.google.com&#8221; when I can just type &#8220;<a href="http://www.google.ca/search?q=gmail&#038;btnI=1">gmail</a>&#8220;? To me, Google has become a kind of DNS &#8212; resolving keywords into a complete URL. At that point, it&#8217;s hardly even search &#8212; it&#8217;s just a convenient side effect.
</p>
<p>
Providing a transparent link resolving service seems like a great selfless gesture by our unevil Google overlords. Rescuing the lazy with transparency and anonymity&#8230; Well, not quite. <strong>It turns out that the <em>I&#8217;m Feeling Lucky</em> feature only really works if you run it from the <a href="http://www.google.com/webhp?hl=en">Google homepage</a></strong>, and approximately half-works from anywhere else.
</p>
<div style="text-align: center; padding: 5px;"><img src="http://shazow.net/temp/wheelofluck.png" title="Wheel of Luck^W Fail" style="border: 0;"/></div>
<h2>Getting technical&#8230;</h2>
<p>
Anyone can turn a normal Google query into an <em>I&#8217;m Feeling Lucky</em> query, just append <code>btnI=1</code> to the end of the URL (contrary to <a href="http://www.google.ca/search?q=google+btnI%3D1..99999+Lucky">popular belief</a>, btnI can take on any value, even empty string).</p>
<p>Let&#8217;s examine the problem. Consider this query:<br />
<a href="http://www.google.ca/search?q=workerpool+site%3Ashazow.net&#038;btnI=1">workerpool site:shazow.net</a><br />
<br />Try opening that link, and then to compare, <a href="http://www.google.ca/webhp?q=workerpool+site%3Ashazow.net">try the same query from google.com</a> by hitting <em>I&#8217;m Feeling Lucky</em>.
</p>
<p>Notice how clicking the link brings you to the Google results page, but the same query from the Google homepage does what it&#8217;s supposed to &#8212; takes you to the first result. It&#8217;s starting to become evident what&#8217;s going on here, but let&#8217;s beat this dead horse into the ground by hand crafting some HTTP requests, for great justice.
</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">$ nc google.com 80
GET /search?q=workerpool+site%3Ashazow.net&amp;btnI=1 HTTP/1.1
User-Agent: Mozilla/5.0 (Oh hai, I can haz redirect?)
&nbsp;
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Date: Thu, 09 Oct 2008 01:07:47 GMT
Expires: -1
Content-Type: text/html; charset=UTF-8
...
&nbsp;
$ nc google.com 80
GET /search?q=workerpool+site%3Ashazow.net&amp;btnI=1 HTTP/1.1
User-Agent: Mozilla/5.0 (Oh hai, I can haz redirect?)
Referer: http://www.google.com/webhp?hl=en
&nbsp;
HTTP/1.1 302 Found
Location: http://shazow.net/blog/2008/04/02/gentoo-rockband-code-and-music/
...</pre></div></div>

<p>
I used <a href="http://en.wikipedia.org/wiki/Netcat">netcat</a> to send a raw socket request (the first two lines) to google.com on port 80, and then Google responded (lines 4 and onwards). There are two requests, one is a vanilla request and the second includes a fake Referer header claiming that I was coming from the Google homepage, which yielded the 302 redirect we want.</p>
<p><p>
Sometimes external I&#8217;m Feeling Lucky links work, other times they don&#8217;t. It appears that Google has some secret threshold to decide when to get in the way of your destination like an angry ceiling cat catapulting itself onto your face. It seems to happen when there&#8217;s a small number of results, or the magic search juice score of the top score is relatively low.
</p>
<h2>Sadface, but what can we do?</h2>
<p>
Google may not be completely selfless, but they&#8217;re still pretty good compared to <a href="http://almerica.blogspot.com/2008/09/podcaster-rejeceted-because-it.html" title="Hint: Apple">some jerkwads</a>. Thankfully, Google provides a <a href="http://code.google.com/apis/gdata/json.html">no-strings-attached search API</a> to their wonderful magic search juice. It&#8217;s not very well advertised (or clearly documented), but once you hunt it down, it&#8217;s simpler than sketching a wrinkly gourd. Observe: <a href="http://ajax.googleapis.com/ajax/services/search/web?v=1.0&#038;q=workerpool+site%3Ashazow.net">Same fail query as above in JSON</a>.
</p>
<p>
Writing your own <em>I&#8217;m Feeling Lucky</em> redirector is a piece of cake. I took the liberty of making one on the Google App Engine with a few bonus features:<br />
<strong><a href="http://302found.appspot.com/">http://302found.appspot.com/</a></strong> (<a href="http://github.com/shazow/302found">source code</a> @ github)</p>
]]></content:encoded>
			<wfw:commentRss>http://shazow.net/blog/2008/10/16/googles-lucky-is-fickle-too/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.636 seconds -->
