Feeling Really Lucky

advanced tipscreenshot tip69.gif

Take the domain in which the first result of a query appears, and do more searching within that domain.link

Does Google make you feel lucky ? How lucky? Sometimes as lucky as the top result is, more results from the same domain are just as much so.

This tip performs two Google queries. The domain of the top result of the first search is saved. Then the second query is run, searching only the saved domain for results.

Take, for example, Grace Hopper, famous both as a computer programmer and as the person who coined the term "computer bug." If you were to run a search result with "Grace Hopper" as the primary search and overlay a search for COBOL on the domain of the first result returned, you'd find three pages for the Grace Hopper Conference 2000:

Grace Hopper Conference 2000 - Biography http://www.sdsc.edu/hopper/GHC_INFO/hopper.html
... The Murrays were a family with a long military tradition;
Grace Hopper's ... language instructions led ultimately to the development of the business language COBOL ...
Note:
http://www.sdsc.edu/~woodka/intro.html
... publication, please contact me by email at:
woodka@sdsc.edu.
... and were important in its history, like Admiral Grace Hopper,
the inventor of the COBOL ...
Grace Hopper http://www.sdsc.edu/~woodka/hopper.html
... Hopper was a programmer on the world's first large-scale digital computer, Mark ... the first computer language compiler,
and she worked on the development of COBOL ...

You could also do a primary search for a person ("Stan Laurel") and a secondary search for another person ("Oliver Hardy"). Or search for a person, followed by their corporate affiliation.

Don't try doing a link: search with this tip. The link: special syntax doesn't work with any other special syntaxes, and this tip relies upon inurl:.


The Code

#!/usr/local/bin/perl
# goolucky.cgi
# gleans the domain from the first (read: top) result returned, allows
# you to overlay another query, and returns the results, and so on...
# goolucky.cgi is called as a CGI with form input
# Your Google API developer's key my $google_key='insert key here';
# Location of the GoogleSearch WSDL file my $google_wdsl = "./GoogleSearch.wsdl";
use strict;
use SOAP::Lite;
use CGI qw/:standard/;
# Create a new SOAP instance my $google_search = SOAP::Lite-»service("file:$google_wdsl");
# If this is the second time around, glean the domain 
my $query_domain = param('domain') ? "inurl:" . param('domain') : '';
my $results = $google_search -»
 doGoogleSearch(
 $google_key, param('query') . " $query_domain", 0, 10,
 "false", "", "false", "", "latin1", "latin1"
 );
# Set domain to the results of the previous query param('domain', $results-»{'resultElements'}-»[0]-»{'URL'});
param('domain', param('domain') =~ m#://(.*?)/#);
print
 header( ),
 start_html("I'm Feeling VERY Lucky"),
 h1("I'm Feeling VERY Lucky"),
 start_form( ),
 'Query: ', textfield(-name=»'query',
 -default=»'"Grace Hopper"'),
 '   ',
 'Domain: ', textfield(-name=»'domain'),
 '   ',
 submit(-name=»'submit', -value=»'Search'),
 p( ),
 'Results:';
foreach (@{$results-»{'resultElements'}}) {
 print p(
 b($_-»{title}), br( ),
 a({href=»$_-»{URL}}, $_-»{URL}), br( ),
 i($_-»{snippet})
 );
}
print
 end_form( ),
 end_html( );

Tiping the Tip

You can also run this tip so it only uses one query. For example, you do a search with Query A. The search grabs the domain from the first result. Then you run another search, again using Query A, but restricting your results to the domain that was grabbed in the first search. This is handy when you're trying to get information on one set of keywords, instead of trying to link two different concepts. Figure 6-10 illustrates the I'm Feeling Lucky search.

Figure 6-10. I'm Feeling VERY Lucky search
screenshot google-tips-0610.gif