Understanding the Google API Query

The core of a Google application is the query. Without the query, there’s no Google data, and without that, you don’t have much of an application. Because of its importance, it’s worth taking a little time to look into the anatomy of a typical query.

Query Essentials

The command in a typical Perl-based Google API application that sends a query to Google looks like:

my $results = $google_search ->
    key, query, start, maxResults, 
    filter, restrict, safeSearch, lr, 
    ie, oe

Usually the items within the parentheses are variables, numbers, or Boolean values (true or false). In the example above, I’ve included the names of the arguments themselves rather than sample values so you can see their definitions here:


This is where you put your Google API developer’s key [Chapter 1]. Without a key, the query won’t get very far.


This is your query, composed of keywords, phrases, and special syntaxes.


Also known as the offset, this integer value specifies at what result to start counting when determining which 10 results to return. If this number were 16, the Google API would return results 16-25. If 300, results 300-309 (assuming, of course, that your query found that many results). This is what’s known as a “zero-based index”; counting starts at 0, not 1. The first result is result 0, and the 999th, 998. It’s a little odd, admittedly, but you get used to it quickly—especially if you go on to do much programming. Acceptable values ...

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.