NAME

Google::Search - Interface to the Google AJAX Search API

VERSION

Version 0.024

SYNOPSIS

my $search = Google::Search->Web( query => "rock" );
my $result = $search->first;
while ( $result ) {
    print $result->rank, " ", $result->uri, "\n";
    $result = $result->next;
}

You can also use the single-argument-style invocation:

Google::Search->Web( "query" )

The following kinds of searches are supported

Google::Search->Local( ... )
Google::Search->Video( ... )
Google::Search->Blog( ... )
Google::Search->News( ... )
Google::Search->Image( ... )
Google::Search->Patent( ... )

You can also take advantage of each service's specialized interface

# The search below specifies the latitude and longitude:
$search = Google::Search->Local( query => { q => "rock", sll => "33.823230,-116.512110" }, ... );

my $result = $search->first;
print $result->streetAddress, "\n";

You can supply an API key and referrer (referer) if you have them

my $key = ... # This should be a valid API key, gotten from:
              # http://code.google.com/apis/ajaxsearch/signup.html

my $referrer = "http://example.com/" # This should be a valid referer for the above key

$search = Google::Search->Web(
    key => $key, referrer => $referrer, # "referer =>" Would work too
    query => { q => "rock", sll => "33.823230,-116.512110" }
);

DESCRIPTION

Google::Search is an interface to the Google AJAX Search API (http://code.google.com/apis/ajaxsearch/).

Currently, their API looks like it will fetch you the top 64 results for your search query.

According to the Terms of Service, you need to sign up for an API key here: http://code.google.com/apis/ajaxsearch/signup.html

Shortcut usage for a specific service

Google::Search->Web

Google::Search->Local

Google::Search->Video

Google::Search->Blog

Google::Search->News

Google::Search->Book

Google::Search->Image

Google::Search->Patent

USAGE

Google::Search->new( ... )

Prepare a new search object (handle)

You can configure the search by passing the following to new:

query           The search phrase to submit to Google
                Optionally, this can also be a hash of parameters to submit. You can
                use the hash form to take advantage of each service's varying interface.
                Make sure to at least include a "q" parameter with your search

service         The service to search under. This can be any of: web,
                local, video, blog, news, book, image, patent

start           Optional. Start searching from "start" rank instead of 0.
                Google::Search will skip fetching unnecessary results

key             Optional. Your Google AJAX Search API key (see Description)

referrer        Optional. A referrer that is valid for the above key
                For legacy purposes, "referer" is an acceptable spelling

Both query and service are required

$search->first

Returns a Google::Search::Result representing the first result in the search, if any.

Returns undef if nothing was found

$search->next

An iterator for $search. Will the return the next result each time it is called, and undef when there are no more results.

Returns a Google::Search::Result

Returns undef if nothing was found

$search->result( <rank> )

Returns a Google::Search::Result corresponding to the result at <rank>

These are equivalent:

$search->result( 0 )

$search->first

$search->all

Returns Google::Search::Result list which includes every result Google has returned for the query

In scalar context an array reference is returned, a list otherwise

An empty list is returned if nothing was found

$search->match( <code> )

Returns a Google::Search::Result list

This method will iterate through each result in the search, passing the result to <code> as the first argument. If <code> returns true, then the result will be included in the returned list

In scalar context this method returns the number of matches

$search->first_match( <code> )

Returns a Google::Search::Result that is the first to match <code>

This method will iterate through each result in the search, passing the result to <code> as the first argument. If <code> returns true, then the result will be returned and iteration will stop.

$search->error

Returns a Google::Search::Error if there was an error with the last search

If you receive undef from a result access then you can use this routine to see if there was a problem

warn $search->error->reason;

warn $search->error->http_response->as_string;

# Etc, etc.

This will return undef if no error was encountered

AUTHOR

Robert Krimen, <rkrimen at cpan.org>

SEE ALSO

REST::Google::Search

BUGS

Please report any bugs or feature requests to bug-google-search at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Google-Search. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Google::Search

You can also look for information at:

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

Copyright 2008 Robert Krimen, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.