net.thauvin.google
Class GoogleSearchBean

java.lang.Object
  extended bynet.thauvin.google.GoogleSearchBean

public class GoogleSearchBean
extends java.lang.Object

Implements methods used to perform searches on Google.

Since:
1.0
Version:
$Revision: 1.8 $, $Date: 2003/10/20 14:14:05 $
Author:
Erik C. Thauvin

Field Summary
static boolean DEFAULT_CACHE
          The default cache flag.
static boolean DEFAULT_FILTER
          The default related-queries filter.
static java.lang.String DEFAULT_LR
          The default language restricts.
static int DEFAULT_MAX_RESULTS
          The default maximum number of results to be returned.
static java.lang.String DEFAULT_RESTRICT
          The default document store restrict.
static boolean DEFAULT_SAFE_SEARCH
          The default SafeSearch.
static java.lang.String DEFAULT_SITE
          The default site.
static int DEFAULT_START
          The default index of the result to be returned.
static java.lang.String DEFAULT_TYPE
          The default filetype.
static java.lang.String NEXT_KEYWORD
          The next keyword.
static java.lang.String PREVIOUS_KEYWORD
          The previous keyword.
 
Constructor Summary
GoogleSearchBean()
          Constructs a new instance of the bean.
GoogleSearchBean(java.lang.String key)
          Constructs a new instance of the bean with the specified authorization key.
 
Method Summary
 java.lang.String getCachedPage(java.lang.String url)
          Returns a cached web page from Google.
 com.google.soap.search.GoogleSearchResult getGoogleSearch(java.lang.String q)
          Returns the GoogleSearch attribute of the GoogleSearchBean object.
 com.google.soap.search.GoogleSearchResult getGoogleSearch(java.lang.String q, int start, int maxResults, boolean filter, java.lang.String restrict, boolean safeSearch, java.lang.String lr)
          Invokes a Google search.
 com.google.soap.search.GoogleSearchResult getGoogleSearch(java.lang.String key, java.lang.String q, int start, int maxResults, boolean filter, java.lang.String restrict, boolean safeSearch, java.lang.String lr)
          Returns the GoogleSearch attribute of the GoogleSearchBean object.
 java.lang.String getKeywords()
          Returns the keywords.
 com.google.soap.search.GoogleSearchResult getResult()
          Returns the results of the search.
 java.lang.String getResultElementProperty(int index, java.lang.String property)
          Returns the specified property of the given element index in the current result set.
 com.google.soap.search.GoogleSearchResultElement[] getResultElements()
          Returns an array of result elements that corresponds to the actual list of search results.
 int getResultElementsCount()
          Returns the count of result elements.
 java.lang.String getResultProperty(java.lang.String property)
          Returns the given property of the result set.
 java.lang.String getSpellingSuggestion(java.lang.String phrase)
          Asks Google to return a spelling suggestion for a word or phrase.
 boolean isKeySet()
          Returns true if the authorization key is set.
 boolean isValidResult()
          Returns true whenever the result set is valid, indicating that a search was performed.
static void main(java.lang.String[] args)
          Demonstration program to perform various Google searches.
 void reset()
          Reset the bean properties.
 void setKey(java.lang.String key)
          Sets the authorization key.
 void setKeywords(java.lang.String keywords)
          Sets the search keywords.
 void setProxyServer(java.lang.String proxyHost, int proxyPort, java.lang.String proxyUserName, java.lang.String proxyPassword)
          Sets the HTTP proxy host, port, user name and password.
 void setProxyServer(java.lang.String proxyHost, java.lang.String proxyPort, java.lang.String proxyUserName, java.lang.String proxyPassword)
          Sets the HTTP proxy host, port, user name and password.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CACHE

public static final boolean DEFAULT_CACHE
The default cache flag.

See Also:
Constant Field Values

DEFAULT_FILTER

public static final boolean DEFAULT_FILTER
The default related-queries filter.

See Also:
Constant Field Values

DEFAULT_LR

public static final java.lang.String DEFAULT_LR
The default language restricts.

See Also:
Constant Field Values

DEFAULT_MAX_RESULTS

public static final int DEFAULT_MAX_RESULTS
The default maximum number of results to be returned.

See Also:
Constant Field Values

DEFAULT_RESTRICT

public static final java.lang.String DEFAULT_RESTRICT
The default document store restrict.

See Also:
Constant Field Values

DEFAULT_SAFE_SEARCH

public static final boolean DEFAULT_SAFE_SEARCH
The default SafeSearch.

See Also:
Constant Field Values

DEFAULT_SITE

public static final java.lang.String DEFAULT_SITE
The default site.

See Also:
Constant Field Values

DEFAULT_START

public static final int DEFAULT_START
The default index of the result to be returned.

See Also:
Constant Field Values

DEFAULT_TYPE

public static final java.lang.String DEFAULT_TYPE
The default filetype.

Since:
1.0.1
See Also:
Constant Field Values

NEXT_KEYWORD

public static final java.lang.String NEXT_KEYWORD
The next keyword.

See Also:
Constant Field Values

PREVIOUS_KEYWORD

public static final java.lang.String PREVIOUS_KEYWORD
The previous keyword.

See Also:
Constant Field Values
Constructor Detail

GoogleSearchBean

public GoogleSearchBean()
Constructs a new instance of the bean.


GoogleSearchBean

public GoogleSearchBean(java.lang.String key)
Constructs a new instance of the bean with the specified authorization key.

Parameters:
key - The authorization key.
Method Detail

setKey

public final void setKey(java.lang.String key)
Sets the authorization key.

Parameters:
key - The key string.

isKeySet

public final boolean isKeySet()
Returns true if the authorization key is set.

Returns:
true or false.

setKeywords

public final void setKeywords(java.lang.String keywords)
Sets the search keywords.

Parameters:
keywords - The keywords
Since:
1.0.1
See Also:
getKeywords()

getKeywords

public final java.lang.String getKeywords()
Returns the keywords.

Returns:
The keywords value.
Since:
1.0.1
See Also:
setKeywords(String)

setProxyServer

public void setProxyServer(java.lang.String proxyHost,
                           java.lang.String proxyPort,
                           java.lang.String proxyUserName,
                           java.lang.String proxyPassword)
Sets the HTTP proxy host, port, user name and password.

Parameters:
proxyHost - The host to use for the HTTP proxy.
proxyPort - The port to use for the HTTP proxy.
proxyUserName - The user name to use for the HTTP proxy.
proxyPassword - The password to use for the HTTP proxy.

setProxyServer

public void setProxyServer(java.lang.String proxyHost,
                           int proxyPort,
                           java.lang.String proxyUserName,
                           java.lang.String proxyPassword)
Sets the HTTP proxy host, port, user name and password.

Parameters:
proxyHost - The host to use for the HTTP proxy.
proxyPort - The port to use for the HTTP proxy.
proxyUserName - The user name to use for the HTTP proxy.
proxyPassword - The password to use for the HTTP proxy.

getResult

public final com.google.soap.search.GoogleSearchResult getResult()
Returns the results of the search.

Returns:
The GoogleSearchResult object.

getResultElements

public final com.google.soap.search.GoogleSearchResultElement[] getResultElements()
Returns an array of result elements that corresponds to the actual list of search results.

Returns:
The array of result elements.

getResultElementsCount

public final int getResultElementsCount()
Returns the count of result elements.

Returns:
The result elements count.
See Also:
getResultElements()

isValidResult

public final boolean isValidResult()
Returns true whenever the result set is valid, indicating that a search was performed.

Returns:
true or false.

getCachedPage

public java.lang.String getCachedPage(java.lang.String url)
                               throws com.google.soap.search.GoogleSearchFault
Returns a cached web page from Google.

Parameters:
url - The page's URL.
Returns:
The HTML code of the cached page.
Throws:
com.google.soap.search.GoogleSearchFault

getGoogleSearch

public com.google.soap.search.GoogleSearchResult getGoogleSearch(java.lang.String q,
                                                                 int start,
                                                                 int maxResults,
                                                                 boolean filter,
                                                                 java.lang.String restrict,
                                                                 boolean safeSearch,
                                                                 java.lang.String lr)
                                                          throws com.google.soap.search.GoogleSearchFault
Invokes a Google search.

Parameters:
q - The Google query.
start - The index of the result to be returned.
maxResults - The maximum number of results to be returned.
filter - The related-queries filter.
restrict - The document store restrict value (e.g.: "linux").
safeSearch - Enable or disable SafeSearch.
lr - The language restricts for the search.
Returns:
The results of the search.
Throws:
com.google.soap.search.GoogleSearchFault

getGoogleSearch

public com.google.soap.search.GoogleSearchResult getGoogleSearch(java.lang.String key,
                                                                 java.lang.String q,
                                                                 int start,
                                                                 int maxResults,
                                                                 boolean filter,
                                                                 java.lang.String restrict,
                                                                 boolean safeSearch,
                                                                 java.lang.String lr)
                                                          throws com.google.soap.search.GoogleSearchFault
Returns the GoogleSearch attribute of the GoogleSearchBean object.

Parameters:
key - The authorization key.
q - The Google query.
start - The index of the result to be returned.
maxResults - The maximum number of results to be returned.
filter - The related-queries filter.
restrict - The document store restrict value (e.g.: "linux").
safeSearch - Enable or disable SafeSearch.
lr - The language restricts for the search.
Returns:
The results of the search.
Throws:
com.google.soap.search.GoogleSearchFault
See Also:
getGoogleSearch(String, int, int, boolean, String, boolean, String)

getGoogleSearch

public com.google.soap.search.GoogleSearchResult getGoogleSearch(java.lang.String q)
                                                          throws com.google.soap.search.GoogleSearchFault
Returns the GoogleSearch attribute of the GoogleSearchBean object.

Parameters:
q - The Google query.
Returns:
The results of the search.
Throws:
com.google.soap.search.GoogleSearchFault
See Also:
getGoogleSearch(String, int, int, boolean, String, boolean, String)

getResultElementProperty

public java.lang.String getResultElementProperty(int index,
                                                 java.lang.String property)
Returns the specified property of the given element index in the current result set.

The properties are:

"summary"Returns the ODP summary text string.
"url"Returns the absolute URL path of the search.
"snippet"Returns a text snippet of the query in context.
"title"Returns the title (HTML) of the search result.
"cachedSize"Returns the size of (size + k) the cached version of the URL, in kilobytes.
"relatedInformationPresent"Returns true when the related: query term is supported for this URL; false, otherwise.
"hostName"Returns the host name.
"directoryTitle"Returns the ODP directory title.
"directoryCategoryName"Returns the ODP directory name of the current ODP category.
"directoryCategoryEncoding"Returns the encoding scheme of the current ODP category.
"relatedQuery"Returns the related query string, suitable for use as a search query string.
For example: related:www.example.com/search?q=vacation%20hawaii
"cachedQuery"Returns the cached query string, suitable for use as a cached query string.
For example: www.example.com/search?q=vacation%20hawaii
"staticQuery"The static query, suitable for display.
For example: www.example.com/search?q=vacation hawaii

Parameters:
index - The element index.
property - The property name.
Returns:
The property value.

getResultProperty

public java.lang.String getResultProperty(java.lang.String property)
Returns the given property of the result set.

The properties are:

"estimatedTotalResultsCount"Returns the estimated total number of results returned for the query.
"startIndex"Returns the index (1-based) of the first search result in the result elements.
"endIndex"Returns the index (1-based) of the last search result in the result elements.
"searchTime"Returns the total server time to process the query, in seconds.
"searchTips"Returns a string providing instructive suggestions on how to use Google.
"searchComments"Returns a string intended for display to the end user. (e.g.: list of removed stop words, etc.)
"documentFiltering"Returns true if filtering was performed on the search results; false otherwise.
"searchQuery"Returns the query string that generated this result.
nextReturns the start index of the next set of results.
previousReturns the start index of the previous set of results.

Parameters:
property - The property name.
Returns:
The property value.

getSpellingSuggestion

public java.lang.String getSpellingSuggestion(java.lang.String phrase)
                                       throws com.google.soap.search.GoogleSearchFault
Asks Google to return a spelling suggestion for a word or phrase.

Parameters:
phrase - The word or phrase to correct the spelling for.
Returns:
The suggested correct spelling, or null if none.
Throws:
com.google.soap.search.GoogleSearchFault

main

public static final void main(java.lang.String[] args)
Demonstration program to perform various Google searches.

The arguments are:

<client-key> (search <query> | cached <URL> | spell <phrase>)

Parameters:
args - The command line arguments.

reset

public void reset()
Reset the bean properties.