Sun Java System Portal Server 7.1 Developer's Guide

Define the SimpleSearch Class

Notice the private helper class SimpleSearch. This is where the search is set up and executed and we will look at it in more detail here. The applet/command line class SearchDemo sets up the arguments for SimpleSearch using either applet or command line parameters. It then calls the SimpleSearch.doSearch(String scope) method to execute the search and display the results. The SimpleSearch constructor takes the location of the search server as an argument. In this way, a single SimpleSearch object can be used repeatedly to run searches against the remote search server.

The SimpleSearch.setSearchfile(String filename) method is used by the main program to direct search results to a file when running in command line mode.


Example 29–2 SimpleSearch Class


/** Performs a simple search and displays its results. */
class SimpleSearch {
    String RDMServer;
    String SearchOutputFile;
    /**
    * SimpleSearch constructor
    * @param rdm - the rdm search server, 
		eg, http://portal.siroe.com:2222/portal/search
    */
    public SimpleSearch(String rdm) {
        System.out.println("Sun Java System Search Java Demo");
        RDMServer = rdm;
    }
    /**
    * @param filename - a file to dump raw Search results into - only
    * use if running from the comand line or an applet with file
    * system access
    */
    public void setSearchfile(String filename) {
        SearchOutputFile = filename;
    }
    /** Execute a search */
    public void doSearch(String scope) throws IOException {
        ...see

Define the SimpleSearch Class


...
    }
}

Before submitting the search, SimpleSearch needs to create a Search object. The constructor for the Search class takes several arguments as discussed previously.


Example 29–3 doSearch Class


/** Execute a search */
public void doSearch(String scope) throws IOException {
    /* The Search class encapsulates the search.
    ** It’s parameters are:
    **  1) the search string
    **  2) the attributes you want returned, comma delimited
    **  3) sort order, comma delimited, - descending, + ascending
    **  4) first hit
    **  5) number of hits
    **  6) query language, eg search, taxonomy-basic, schema-basic, etc
    **  7) database to search
    **  8) The RDM server URL, eg, http://portal.siroe.com:2222/ps/search
    **  9) Access token (null for anonymous access, or valid iPlanet 
				Directory Server Access Management Edition session id)
    */
    Search  search = new Search(
        scope,
        "score,url,title,description",
        "-score",
        1,
        20,
        "search",
        null,
        RDMServer,
        null
    );

The Search constructor arguments used here are:

scope

The search scope is the actual query run by the search server. It is the scope argument to doSearch() and ultimately derives from either the applet input panel or a command line argument to the main program.

viewAttributes = "score,url,title,description"

The requested attribute set shown here will result in the server returning the score, url, title, and description of all documents that match the query.

viewOrder = "-score"

A comma delimited list of the attributes to be used to sort the results. A minus sign indicates descending order, a plus sign indicates ascending order. In this case, sort the results by decreasing numerical score value, and use alphabetical order of the title as the secondary sort order.

firstHit = 1

The hit number of the first returned result.

viewHits = 20

The maximum number of results to return.

queryLanguage = "search"

The search server query language. Use search for normal searches.

RDMServer

The URL of the remote search engine, specified as an argument to the SimpleSearch constructor.

ssoToken = null

The Access Manager software single sign on token. Not used in this case, implying anonymous search.