To create a link for each Did You Mean alternative, your Web application code should look similar to these examples.
Note that it is important to display all the DYM alternatives (rather than just the first DYM alternative) because the user’s desired query may not be the first alternative in the list of returned DYM options.
Example 88. Java example
// Get the Map of ESearchReport objects
Map dymRecSrchRpts = nav.getESearchReports();
if (dymRecSrchRpts.size() > 0) {
// Get the user's search key
String searchKey = request.getParameter("Ntk");
if (searchKey != null) {
if (dymRecSrchRpts.containsKey(searchKey)) {
// Get the List of ERecSearchReports for the user's search key
List searchReportList = (List)dymRecSrchRpts.get(searchKey);
// for each report, get the list of Did You Mean objects
for (Iterator i = searchReportList.Iterator(); i.hasNext();) {
ESearchReport searchReport = (ESearchReport)i.next();
// Get the List of Did You Mean objects
List dymList = searchReport.getDYMSuggestions();
// Get all Did You Mean objects to display each available
// DYM alternative.
for (Iterator j = dymList.Iterator(); j.hasNext();) {
ESearchDYMSuggestion dymSug =
(ESearchDYMSuggestion)j.next();
String sug_val = dymSug.getTerms();
String sug_num =
String.valueOf(dymSug.getNumMatchingResults());
String sug_sid = (String)request.getAttribute("sid");
if (sug_val != null) {
...
// Adjust URL parameters to create new search query
UrlGen urlg =
new UrlGen(request.getQueryString(), "UTF-8");
urlg.removeParam("Ntt");
urlg.addParam("Ntt", sug_val);
urlg.removeParam("Ntpc");
urlg.addParam("Ntpc", "1");
urlg.removeParam("Ntpr");
urlg.addParam("Ntpr", "0");
String url = CONTROLLER+"?"+urlg;
// Display Did You Mean link for each DYM alternative
%>Did You Mean <a href="<%=url%>">
<%= sug_val %></a><%
}
}
}
}
}
}
Example 89. .NET example
// Get the Dictionary of ESearchReport objects
IDictionary dymRecSrchRpts = nav.ESearchReports;
// Get the user's search key
String dymSearchKey = Request.QueryString["Ntk"];
if (dymSearchKey != null) {
if (dymRecSrchRpts.Contains(dymSearchKey)) {
// Get the list of Search Report objects
IList srchReportList = (IList)recSrchRpts[searchKey];
// for each report, display all its DYM suggestions
foreach (object srObj in srchReportList) {
// Get the List of Did You Mean objects
IList dymList = ((ESearchReport)srObj).DYMSuggestions;
foreach (object dymObj in dymList) {
ESearchDYMSuggestion dymSug = (ESearchDYMSuggestion)dymObj;
String sug_val = dymSug.Terms;
String sug_num = dymSug.NumMatchingResults.ToString();
// Adjust URL parameters to create new search query
UrlGen urlg =
new UrlGen(Request.Url.Query.Substring(1),"UTF-8");
urlg.RemoveParam("Ntt");
urlg.AddParam("Ntt", sug_val);
urlg.RemoveParam("Ntpc");
urlg.AddParam("Ntpc", "1");
urlg.RemoveParam("Ntpr");
urlg.AddParam("Ntpr", "0");
urlg.AddParam("sid",Request.QueryString["sid"]);
String url = Application["CONTROLLER"].ToString()+"?"+urlg;
// Display Did You Mean message and link
// for each DYM option
%>Did You Mean <a href="<%= url %>">
<%= sug_val %></a>?<%
}
}
}
}

