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:
Get all the
Supplement
objects from theNavigation
object, which will be encapsulated in aSupplementList
object (note that the list can also include non-clusterSupplement
objects):SupplementList navsups = nav.getSupplements();
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();
Get the value of the
Dgraph.SeeAlsoCluster
property:String clustersPropName = (String)propsMap.get("DGraph.SeeAlsoCluster");
Test the value returned from the
Dgraph.SeeAlsoCluster
property. If it is null, then thisSupplement
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)
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 theclustersOn
variable to true (so that the header will not be displayed again):if (!clustersOn) { // display title ... clustersOn = true; }
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); }
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('"'); }
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 anERecSearchList
) to determine if the cluster selection is already active in the searches.UrlENEQuery newq = new UrlENEQuery(request.getQueryString(),"UTF-8"); ERecSearchList searches = newq.getNavERecSearches();
Create a new search (an
ERecSearch
object), using theclusterPartial
search interface as the search key, the list of related terms (in theclusterSpace
variable) as the terms for the search, and mode matchpartial as the search option (which specifiesMatchPartial
as the search mode).ERecSearch newSearch = new ERecSearch("clustersPartial", clusterSpace, "mode matchpartial");
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); ... }
Loop back to step 2 to get another
Supplement
object. The loop is done when all the objects in theSupplementList
have been retrieved.Display the clusters, which are stored as a list of strings in the
clusterStrings
variable. TheclusterUrls
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.