com.google.soap.search
Class GoogleSearch

java.lang.Object
  |
  +--com.google.soap.search.GoogleSearch

public class GoogleSearch
extends java.lang.Object

The GoogleSearch class encapsulates access to the Google Web APIs. It provides access to search and cached page functions via SOAP. Examples of use:

   GoogleSearch search = new GoogleSearch();
   // Set mandatory attributes
   search.setKey("000000000000000000000000");
   search.setQueryString("Internet standards");
   // Set optional attributes
   search.setSafeSearch(true);
   // Invoke the actual search
   GoogleSearchResult result = search.doSearch();
   // process the result
 
   GoogleSearch cache = new GoogleSearch();
   cache.setKey("00000000000000000000");
   String page = cache.doGetCachedPage("http://www.google.com/");
 

See Also:
GoogleSearchFault, GoogleSearchResult, GoogleSearchResultElement, GoogleSearchDirectoryCategory

Constructor Summary
GoogleSearch()
          Construct a new instance of a GoogleSearch client.
 
Method Summary
protected  com.google.soap.search.Call constructCall(java.lang.String methodName, java.util.Vector parameters)
           
 byte[] doGetCachedPage(java.lang.String url)
          Retrieve a cached web page from Google.
 GoogleSearchResult doSearch()
          Invoke the Google search.
 java.lang.String doSpellingSuggestion(java.lang.String phrase)
          Ask Google to return a spelling suggestion for a word or phrase.
 void setFilter(boolean on)
          Enable or disable the "related-queries" filter.
 void setInputEncoding(java.lang.String ie)
          Deprecated. The server expects all API calls with UTF-8 encoding.
 void setKey(java.lang.String key)
          Set the user key used for authorization by Google SOAP server.
 void setLanguageRestricts(java.lang.String lr)
          Set the language restricts for the search.
 void setMaxResults(int maxResults)
          Set the maximum number of results to be returned.
 void setOutputEncoding(java.lang.String oe)
          Deprecated. The server expects all API calls with UTF-8 encoding.
 void setProxyHost(java.lang.String host)
          Set a host to use as an HTTP proxy.
 void setProxyPassword(java.lang.String password)
          Set the username required for the HTTP proxy.
 void setProxyPort(int port)
          Set a port to use as an HTTP proxy.
 void setProxyUserName(java.lang.String name)
          Set the username required for the HTTP proxy.
 void setQueryString(java.lang.String q)
          Set the query string for this search.
 void setRestrict(java.lang.String restrict)
          Set the restrict.
 void setSafeSearch(boolean safeSearch)
          Enable or disable SafeSearch.
 void setSoapServiceURL(java.lang.String soapServiceURL)
          Set the URL of the Google SOAP Search service.
 void setStartResult(int start)
          Set the index of the first result to be returned.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GoogleSearch

public GoogleSearch()
Construct a new instance of a GoogleSearch client.
Method Detail

setKey

public void setKey(java.lang.String key)
Set the user key used for authorization by Google SOAP server. This is a mandatory attribute for all requests.

setSoapServiceURL

public void setSoapServiceURL(java.lang.String soapServiceURL)
Set the URL of the Google SOAP Search service. This defaults to Google's SOAP endpoint, but you can override it here or by setting the property google.soapEndpointURL. An HTTP proxy that displays SOAP requests can be very helpful for displaying debug info.

setQueryString

public void setQueryString(java.lang.String q)
Set the query string for this search.

setStartResult

public void setStartResult(int start)
Set the index of the first result to be returned. For instance if there are 137 results, you may want to start at 20.

setMaxResults

public void setMaxResults(int maxResults)
Set the maximum number of results to be returned.

setFilter

public void setFilter(boolean on)
Enable or disable the "related-queries" filter. This filter eliminates results that are very similar.

setRestrict

public void setRestrict(java.lang.String restrict)
Set the restrict. This allows you to restrict the search to a specific document store such as "unclesam" or "linux".

setSafeSearch

public void setSafeSearch(boolean safeSearch)
Enable or disable SafeSearch. When SafeSearch is turned on, sites and web pages containing pornography and explicit sexual content are blocked from search results. While no filter is 100% accurate, Google's filter uses advanced proprietary technology that checks keywords and phrases, URLs and Open Directory categories.

setLanguageRestricts

public void setLanguageRestricts(java.lang.String lr)
Set the language restricts for the search.
Parameters:
lr - List of languages separated by | vertical bar characters. Example value (German and French): lang_de|lang_fr

setInputEncoding

public void setInputEncoding(java.lang.String ie)
Deprecated. The server expects all API calls with UTF-8 encoding.

Set the input encoding.

setOutputEncoding

public void setOutputEncoding(java.lang.String oe)
Deprecated. The server expects all API calls with UTF-8 encoding.

Set the output encoding.

setProxyHost

public void setProxyHost(java.lang.String host)
Set a host to use as an HTTP proxy. If unset, GoogleSearch will also check the Java system properties "http.proxyHost" and "http.proxyPort" and use those values. If those are also unset, HTTP requests go direct with no proxy.

setProxyPort

public void setProxyPort(int port)
Set a port to use as an HTTP proxy. Only used if proxyHost is also set. If unset, port 80 is assumed to be the default.

setProxyUserName

public void setProxyUserName(java.lang.String name)
Set the username required for the HTTP proxy. Only used if proxyHost is also set.

setProxyPassword

public void setProxyPassword(java.lang.String password)
Set the username required for the HTTP proxy. Only used if proxyHost is also set.

doSearch

public GoogleSearchResult doSearch()
                            throws GoogleSearchFault
Invoke the Google search. Note: key and query attributes must already be set.
Returns:
GoogleSearchResult, the results of the search.
Throws:
GoogleSearchFault - If a) mandatory attributes were not set, b) anything goes wrong on the server side, or c) anything goes wrong with the connection.
See Also:
GoogleSearchFault, GoogleSearchResult, GoogleSearchResultElement, GoogleSearchDirectoryCategory

doGetCachedPage

public byte[] doGetCachedPage(java.lang.String url)
                       throws GoogleSearchFault
Retrieve a cached web page from Google. The key attribute must be set.
Parameters:
url - The url of the page to retrieve the cached version of.
Returns:
String containing HTML code of the cached page.
Throws:
GoogleSearchFault - If a) mandatory attributes were not set, b) anything goes wrong on the server side, or c) anything goes wrong with the connection.
See Also:
GoogleSearchFault

doSpellingSuggestion

public java.lang.String doSpellingSuggestion(java.lang.String phrase)
                                      throws GoogleSearchFault
Ask Google to return a spelling suggestion for a word or phrase.
Parameters:
key - Identifies the user for query limiting and authorization.
phrase - The word or phrase to correct the spelling for
Returns:
Suggested corrected spelling, or null if none.
Throws:
GoogleSearchFault - If a) key is invalid, or daily query limit for the key was reached. b) anything goes wrong on the server side. c) anything goes wrong with the connection.

constructCall

protected com.google.soap.search.Call constructCall(java.lang.String methodName,
                                                    java.util.Vector parameters)