You can add a new nav_clusters.jsp file for rendering clusters.

Appendix A of this guide includes a new nav_clusters.jsp file that can be used as a template for rendering cluster contents. This file should be included at the end of the nav_controls.jsp file. Note that it is recommended that you display clusters only if there are two or more.

The highlights of this file are as follows:

  1. Get all the Supplement objects from the Navigation object, which will be encapsulated in a SupplementList object (note that the list can also include non-cluster Supplement objects):

    SupplementList navsups = nav.getSupplements();
  2. Within a For loop (labeled supLoop), get a Supplement object and then get that object’s properties:

    Supplement sup = (Supplement)navsups.get(I);
    PropertyMap propsMap = sup.getProperties();
  3. Get the value of the Dgraph.SeeAlsoCluster property:

    String clustersPropName = (String)propsMap.get("DGraph.SeeAlsoCluster");
  4. Test the value returned from the Dgraph.SeeAlsoCluster property. If it is null, then this Supplement object is not a cluster and we should loop back to step 2; if the value is non-null, then this is a cluster and we continue to step 5:

    if (clustersPropName != null)
  5. If this is the first discovered cluster, then the clustersOn variable will be set to false. Therefore, first display the Cluster Discovery header and then set the clustersOn variable to true (so that the header will not be displayed again):

    if (!clustersOn) {
       // display title
       ...
       clustersOn = true;
    }
  6. Get the ranking (ClusterRank property) of the cluster and the number of terms (NTerms property) it contains. The returned string values are then transformed to integers:

    String rankString = (String)propsMap.get("ClusterRank");
    String nTermsString = (String)propsMap.get("NTerms");
    int rank;
    int nTerms;
    try {
       rank = Integer.parseInt(rankString);
       nTerms = Integer.parseInt(nTermsString);
    }
  7. Within a For loop, retrieve the terms from the NTerms property and format them by separating them with commas and spaces. The list of terms will then be:

    StringBuffer termsSB = new StringBuffer();
    StringBuffer termsSBSpace = new StringBuffer();
    for (int iTerm = 0; iTerm < nTerms; ++iTerm) {
       String term = (String)propsMap.get("Term_"+iTerm);
       ...
       if (termsSB.length() != 0) {
          termsSB.append(", ");
          termsSBSpace.append(" ");
       }
       termsSB.append(term);
       termsSBSpace.append('"').append(term).append('"');
    }
  8. For a given cluster, begin to create a UrlENEQuery request (using the current request), in case the user wants to click on that cluster. Also get the current navigation searches (as an ERecSearchList) to determine if the cluster selection is already active in the searches.

    UrlENEQuery newq = new UrlENEQuery(request.getQueryString(),"UTF-8");
    ERecSearchList searches = newq.getNavERecSearches();
  9. Create a new search (an ERecSearch object), using the clusterPartial search interface as the search key, the list of related terms (in the clusterSpace variable) as the terms for the search, and mode matchpartial as the search option (which specifies MatchPartial as the search mode).

    ERecSearch newSearch = new ERecSearch("clustersPartial",
       clusterSpace, "mode matchpartial");
  10. Test whether the current navigation searches are null or do not contain the new search (from step 9). If the test is true, then the new search can be added to the UrlENEQuery request; if it is false, do not add the new search because the cluster selection is already active.

    if (searches == null || !searches.contains(newSearch)) {
       ...
       searches.add(newSearch);
       newq.setNavERecSearches(searches);
       ...
    }
  11. Loop back to step 2 to get another Supplement object. The loop is done when all the objects in the SupplementList have been retrieved.

  12. Display the clusters, which are stored as a list of strings in the clusterStrings variable. The clusterUrls variable is a list of the cluster URLs:

    for (int I = 0; I < clusterStrings.size(); ++I) {
       %><tr><td><img src="b.gif" width=10></td>
       <td width="100%"><font face="arial" size="1" color="gray">
       > <a href="<%= clusterUrls.get(I) %>">
       <font face="arial" size="1" color="blue">
       <%= clusterStrings.get(I) %></font></a>
       </td></tr><%
    }

The following is an abbreviated example of the JSP reference implementation showing the clusters rendered by the nav_clusters.jsp file. Clicking on a cluster link will execute the partial match query built by steps 8-10.


Copyright © Legal Notices