This
nav_clusters.jsp
sample file is used to render
clusters that are generated by the Cluster Discovery feature.
This file should be included in the
nav_controls.jsp
file.
<%---------------------------------------------------------------------- DESCRIPTION: This module demonstrates the Cluster Discovery feature. It displays clusters received as Supplemental Objects, makes them selectable, and, upon selection, generates a search based on the selected clusters. This module is included in the nav_controls.jsp module. Copyright (C) 2008 by Endeca Technologies - COMPANY CONFIDENTIAL -----------------------------------------------------------------------%> <% // Get supplemental list SupplementList navsups = nav.getSupplements(); boolean clustersOn = false; // lazily allocated: List<String> clusterUrls = null; List<String> clusterStrings = null; // Loop over cluster supplemental objects supLoop: for (int i = 0; i < navsups.size(); ++i) { // Get individual see also object Supplement sup = (Supplement)navsups.get(i); // Get property map PropertyMap propsMap = sup.getProperties(); String clustersPropName = (String)propsMap.get("DGraph.SeeAlsoCluster"); if (clustersPropName != null) { if (!clustersOn) { // display title %> <table border="0" cellspacing="0" cellpadding="0" width="100%"> <tr><td colspan="5" bgcolor="orange"> <font face="arial" size=2 color="white"> Cluster Discovery</font></td></tr> <tr><td colspan="5"><img src="b.gif" height=3></td></tr> <% clustersOn = true; } // end of if !clustersOn 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); } catch (NumberFormatException e) { // add code here to log error continue supLoop; } // end of catch StringBuffer termsSB = new StringBuffer(); StringBuffer termsSBSpace = new StringBuffer(); for (int iTerm = 0; iTerm < nTerms; ++iTerm) { String term = (String)propsMap.get("Term_"+iTerm); if (term == null) { // add code to log error continue supLoop; } if (termsSB.length() != 0) { termsSB.append(", "); termsSBSpace.append(" "); } // end of if termsSB.length termsSB.append(term); termsSBSpace.append('"').append(term).append('"'); } // end of for terms String clusterX = termsSB.toString(); String clusterSpace = termsSBSpace.toString(); // Create request to follow a cluster selection // (unless cluster selection already active in the searches) UrlENEQuery newq = new UrlENEQuery(request.getQueryString(), "UTF-8"); ERecSearchList searches = newq.getNavERecSearches(); ERecSearch newSearch = new ERecSearch("All", clusterSpace, "mode matchpartial"); if (searches == null || !searches.contains(newSearch)) { if (searches == null) searches = new ERecSearchList(); if (clusterUrls == null) { clusterUrls = new ArrayList<String>(); clusterStrings = new ArrayList<String>(); } // end of if clusterUrls searches.add(newSearch); newq.setNavERecSearches(searches); UrlGen hostportq = new UrlGen("", "UTF-8"); hostportq.addParam("eneHost", (String)request.getAttribute("eneHost")); hostportq.addParam("enePort", (String)request.getAttribute("enePort")); String url = CONTROLLER + "?" + hostportq.toString() + "&" + UrlENEQuery.toQueryString(newq, "UTF-8"); clusterUrls.add(url); clusterStrings.add(clusterX); } // end of if searches } // end of if clusterPropName != null } // end of if clusterPropName != null if (clusterStrings != null && clusterStrings.size() > 1) { // display clusters only if at least 2. 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> <% } // end of for clusterStrings } // end of if clusterStrings if (clustersOn) { // close table %> <tr><td colspan="2"><img src="b.gif" height=30></td></tr> </table> <% }%> // end of if clusterOn