edu.ubc.cpsc.googlex
Class SimpleGoogleSearch

java.lang.Object
  extended by edu.ubc.cpsc.googlex.SimpleGoogleSearch

public class SimpleGoogleSearch
extends java.lang.Object

A simple class to search Google using JSON and the Google AJAX Search API.


Constructor Summary
SimpleGoogleSearch()
          Default Constructor
 
Method Summary
 boolean doSearch(java.lang.String queryString)
          Search for the given query, that is, a string you might type into Google when performing a search.
 int getHitCount()
          Get the number of hits the latest search produced.
 int getNumResults()
          Gets the number of search results (i.e., snippets) from the latest search.
 java.lang.String getSnippetAt(int index)
          The snippet Google returned for the search result with the given index.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleGoogleSearch

public SimpleGoogleSearch()
Default Constructor

Method Detail

doSearch

public boolean doSearch(java.lang.String queryString)
Search for the given query, that is, a string you might type into Google when performing a search.

Parameters:
queryString - a query (non-null)
Returns:
true if the search succeeds (i.e., encounters no errors, even if it doesn't return any results) and false otherwise

getHitCount

public int getHitCount()
Get the number of hits the latest search produced.

Returns:
the number of hits or -1 if there has not yet been a search or if the last search failed

getNumResults

public int getNumResults()
Gets the number of search results (i.e., snippets) from the latest search.

Returns:
the number of search results or 0 if there has not yet been a search or if the last search failed

getSnippetAt

public java.lang.String getSnippetAt(int index)
The snippet Google returned for the search result with the given index.

Parameters:
index - a number between 0 and getNumResults - 1. NOTE THAT THIS STARTS AT ZERO!
Returns:
the snippet at the given index