GSA-JAPI: Java API for interacting with the Google Search Appliance™

Please take a moment to read the license before using this library.
This project is neither affiliated to nor sponsored by Google®.
Google® and Google Search Appliance™ are registered trademarks of Google Inc.

API usage

This is basically a walk through of the source code of GSAClientDemo class included with the source distribution. For the sake of convenience, the source code is included below:
package net.sf.gsaapi.demo;

import java.util.List;

import net.sf.gsaapi.GSAClient;
import net.sf.gsaapi.GSAQuery;
import net.sf.gsaapi.GSAResponse;
import net.sf.gsaapi.GSAResult;
import net.sf.gsaapi.GSAQuery.GSAQueryTerm;

public class GSAClientDemo {
// target GSA's hostname
private static final String HOSTNAME = "";
// query string to search for
private static final String QUERY_STRING = "java sdk";
// The value for the frontend configured for the GSA
    // (If you dont know this, ask GSA admin for correct value for your target GSA.)
private static final String SETTING_FRONTEND = "default_frontend";

public static void main(String[] args) throws Exception {
GSAClient client = new GSAClient(HOSTNAME)
        GSAQuery query =
new GSAQuery();
// typical way to generate query term.
GSAQueryTerm term = new GSAQueryTerm(QUERY_STRING);
("Searching for: "+query.getQueryString());
// above 2 lines may be equivalently replaced by:
        // query.setAndQueryTerms(new String[]{QUERY_STRING});

query.setFrontend(SETTING_FRONTEND); // required!
GSAResponse response = client.getGSAResponse(query);
("Found " + response.getNumResults() + " results");
        List results = response.getResults
("Showing top " + results.size() + " results");
("[To get more top N results, use query.setMaxResults(int)]");
for (int i=0, iSize=results.size(); i<iSize; i++) {
GSAResult result = (GSAResult) results.get(i);
(result.getRating() +"\t" + result.getTitle());
  1. Constants:
    HOSTNAME is the hostname of the Search Appliance.
    QUERY_STRING is the search "query" we are using for this demo.
    SETTING_FRONTEND is a value configured by the administrator of the search appliance. This is the value of the "client" request parameter.
  2. To begin, you must construct a new instance of GSAClient. The constructor requires the hostname parameter. GSAClient instantiation is a one time step, the same instance can be reused for making multiple queries to the same host.
  3. Querying the search appliance requires you to create an instance of GSAQuery. In the simplest case, a GSAQuery requires you to set the GSAQueryTerm instance that encapsulates the search string. (If you have used the standard browser user interface, you can think of the GSAQueryTerm as the class that holds information that goes in the search textfield.)
  4. Once the query object is prepared, you can use the client instance created in step 2 to get the GSAResponse object. The GSAResponse object contains a List of GSAResult objects.