Searching Google Topics

A hack that runs a query against some of the available Google API specialty topics.

Google doesn’t talk about it much, but it does make specialty web searches available. And I’m not just talking about searches limited to a certain domain. I’m talking about searches that are devoted to a particular topic. The Google API makes four of these searches available: The U.S. Government, Linux, BSD, and Macintosh.

In this hack, we’ll look at a program that takes a query from a form and provides a count of that query in each specialty topic, as well as a count of results for each topic. This program runs via a form.

Why Topic Search?

Why would you want to topic search? Because Google currently indexes over 3 billion pages. If you try to do more than very specific searches you might find yourself with far too many results. If you narrow your search down by topic, you can get good results without having to exactly zero in on your search.

You can also use it to do some decidedly unscientific research. Which topic contains more iterations of the phrase “open source”? Which contains the most pages from .edu (educational) domains? Which topic, Macintosh or FreeBSD, has more on user interfaces? Which topic holds the most for Monty Python fans?

The Code

#!/usr/local/bin/perl # gootopic.cgi # Queries across Google Topics (and All of Google), returning # number of results and top result for each topic. # gootopic.cgi is called as a CGI with form input # Your Google API developer's ...

Get Google Hacks now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.