Search the web using the Google Search Control

Before you can use the Google Web APIs, you need to register with Google and obtain a Google Key. You need to configure the Google Control with this key, as described in the section on configuring the Google Control.

The Google Control provides two methods to perform an internet search. The first is a simple method that takes as parameters the query string and an index into the search results. The second accepts a more complete parameter list and allows more control over the search operation. Both methods are detailed below.

Simple search method

The simple search method is invoked as follows:
String query = "Weblogic Workshop"
int start = 0;
GoogleSearchResult var = control.googleSearch( query, start);
This will return ten results for the query "Weblogic Workshop", starting at result element 0.  The behaviour of this method can be tweaked by configuring some or all of the properties provided by the control, documented here.

Extended search method

The extended search method is invoked as follows:
String query = "Weblogic Workshop"
int start = 0;
int maxResults = 10;
boolean filter = true;
String restrict = "countryUS";
boolean safeSearch = true;
String languageRestrict = "lang_en";
GoogleSearchResult var = control.googleSearchExtended( query,
start,
maxResults,
filter,
restrict,
safeSearch,
languageRestrict);

This will return ten results for the query "Weblogic Workshop", starting at result element, from web sites hosted in the US and whose content is in the English language.  Additionally the results will be filtered for adult content and duplicates.

Using the results from the Google Search Control

The GoogleSearchResult type returned by the search methods contains both data associated with the search itself, and data associated with each match.  The data associated with the search itself include items like total search time, the query used, the total number of possible matches etc.  The data associated with each match is retrieved as follows:

GoogleSearchResult var = control.googleSearch( query, start);
ResultElement[] matches = var.resultElements;
The ResultElement type contains fields like a summary of the matches page, the URL to that page, the title of the match and a snippet of content etc.