Handle search error message from Freemarker controller and template.
This commit is contained in:
parent
73024a4d03
commit
589383f15b
3 changed files with 50 additions and 55 deletions
|
@ -119,8 +119,7 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
|
||||||
if( vreq.getWebappDaoFactory() == null
|
if( vreq.getWebappDaoFactory() == null
|
||||||
|| vreq.getWebappDaoFactory().getIndividualDao() == null ){
|
|| vreq.getWebappDaoFactory().getIndividualDao() == null ){
|
||||||
log.error("makeUsableBeans() could not get IndividualDao ");
|
log.error("makeUsableBeans() could not get IndividualDao ");
|
||||||
//doSearchError(request, response, "Could not access Model", portalFlag);
|
return doSearchError("Could not access Model.", config);
|
||||||
//return;
|
|
||||||
}
|
}
|
||||||
IndividualDao iDao = vreq.getWebappDaoFactory().getIndividualDao();
|
IndividualDao iDao = vreq.getWebappDaoFactory().getIndividualDao();
|
||||||
VClassGroupDao grpDao = vreq.getWebappDaoFactory().getVClassGroupDao();
|
VClassGroupDao grpDao = vreq.getWebappDaoFactory().getVClassGroupDao();
|
||||||
|
@ -157,8 +156,7 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
|
||||||
log.debug("query for '" + qtxt +"' is " + query.toString());
|
log.debug("query for '" + qtxt +"' is " + query.toString());
|
||||||
|
|
||||||
if (query == null ) {
|
if (query == null ) {
|
||||||
//doNoQuery(vreq, response);
|
return doNoQuery(config, portal);
|
||||||
//return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexSearcher searcherForRequest = getIndexSearcher(indexDir);
|
IndexSearcher searcherForRequest = getIndexSearcher(indexDir);
|
||||||
|
@ -175,23 +173,22 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
|
||||||
}catch (Exception ex){
|
}catch (Exception ex){
|
||||||
log.error(ex);
|
log.error(ex);
|
||||||
String msg = makeBadSearchMessage(qtxt,ex.getMessage());
|
String msg = makeBadSearchMessage(qtxt,ex.getMessage());
|
||||||
if(msg == null ) msg = "<p>The search request contained errors.</p>";
|
if (msg == null) {
|
||||||
//doFailedSearch(vreq, response, msg, qtxt);
|
msg = "The search request contained errors.";
|
||||||
//return;
|
}
|
||||||
|
return doFailedSearch(msg, qtxt, config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( topDocs == null || topDocs.scoreDocs == null){
|
if( topDocs == null || topDocs.scoreDocs == null){
|
||||||
log.error("topDocs for a search was null");
|
log.error("topDocs for a search was null");
|
||||||
String msg = "<p>The search request contained errors.</p>";
|
String msg = "The search request contained errors.";
|
||||||
//doFailedSearch(request, response, msg, qtxt);
|
return doFailedSearch(msg, qtxt, config);
|
||||||
//return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int hitsLength = topDocs.scoreDocs.length;
|
int hitsLength = topDocs.scoreDocs.length;
|
||||||
if ( hitsLength < 1 ){
|
if ( hitsLength < 1 ){
|
||||||
//doFailedSearch(request, response, NORESULT_MSG, qtxt);
|
return doNoHits(qtxt, config);
|
||||||
//return;
|
|
||||||
}
|
}
|
||||||
log.debug("found "+hitsLength+" hits");
|
log.debug("found "+hitsLength+" hits");
|
||||||
|
|
||||||
|
@ -273,7 +270,7 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
|
||||||
if ( !StringUtils.isEmpty(classGroupParam) ) {
|
if ( !StringUtils.isEmpty(classGroupParam) ) {
|
||||||
VClassGroup grp = grpDao.getGroupByURI(classGroupParam);
|
VClassGroup grp = grpDao.getGroupByURI(classGroupParam);
|
||||||
if( grp != null && grp.getPublicName() != null )
|
if( grp != null && grp.getPublicName() != null )
|
||||||
body.put("classgroupName", grp.getPublicName());
|
body.put("classGroupName", grp.getPublicName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !StringUtils.isEmpty(typeParam) ) {
|
if ( !StringUtils.isEmpty(typeParam) ) {
|
||||||
|
@ -286,8 +283,7 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
log.error(e, e);
|
log.error(e, e);
|
||||||
//doSearchError(request, response, e.getMessage(), null);
|
return doSearchError(e.getMessage(), config);
|
||||||
//return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mergeBodyToTemplate("pagedSearchResults.ftl", body, config);
|
return mergeBodyToTemplate("pagedSearchResults.ftl", body, config);
|
||||||
|
@ -743,37 +739,35 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doNoQuery(HttpServletRequest request,
|
private String doSearchError(String message, Configuration config) {
|
||||||
HttpServletResponse response)
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
throws ServletException, IOException {
|
body.put("message", "Search failed: " + message);
|
||||||
Portal portal = (new VitroRequest(request)).getPortal();
|
return mergeBodyToTemplate("searchError.ftl", body, config);
|
||||||
request.setAttribute("title", "Search "+portal.getAppName());
|
|
||||||
request.setAttribute("bodyJsp", Controllers.SEARCH_FORM_JSP);
|
|
||||||
|
|
||||||
RequestDispatcher rd = request
|
|
||||||
.getRequestDispatcher(Controllers.BASIC_JSP);
|
|
||||||
rd.forward(request, response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doFailedSearch(HttpServletRequest request,
|
private String doNoQuery(Configuration config, Portal portal) {
|
||||||
HttpServletResponse response, String message, String querytext)
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
throws ServletException, IOException {
|
body.put("title", "Search " + portal.getAppName());
|
||||||
Portal portal = (new VitroRequest(request)).getPortal();
|
body.put("message", "No query entered.");
|
||||||
if( querytext != null ){
|
return mergeBodyToTemplate("searchError.ftl", body, config);
|
||||||
request.setAttribute("querytext", querytext);
|
}
|
||||||
request.setAttribute("title", querytext+" - "+portal.getAppName()+" Search" );
|
|
||||||
}else{
|
private String doFailedSearch(String message, String querytext, Configuration config) {
|
||||||
request.setAttribute("title", portal.getAppName()+" Search" );
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
request.setAttribute("querytext", "");
|
body.put("title", "Search for '" + querytext + "'");
|
||||||
|
if ( StringUtils.isEmpty(message) ) {
|
||||||
|
message = "Search failed.";
|
||||||
}
|
}
|
||||||
if( message != null && message.length() > 0)
|
body.put("message", message);
|
||||||
request.setAttribute("message", message);
|
return mergeBodyToTemplate("searchError.ftl", body, config);
|
||||||
|
|
||||||
request.setAttribute("bodyJsp", Controllers.SEARCH_FAILED_JSP);
|
|
||||||
RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
|
|
||||||
rd.forward(request, response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String doNoHits(String querytext, Configuration config) {
|
||||||
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
|
body.put("title", "Search for '" + querytext + "'");
|
||||||
|
body.put("message", "No matching results.");
|
||||||
|
return mergeBodyToTemplate("searchError.ftl", body, config);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes a message to display to user for a bad search term.
|
* Makes a message to display to user for a bad search term.
|
||||||
|
@ -831,15 +825,7 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
|
||||||
return opBlacklist;
|
return opBlacklist;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doSearchError(HttpServletRequest request,
|
|
||||||
HttpServletResponse response, String message, Object object)
|
|
||||||
throws ServletException, IOException {
|
|
||||||
Portal portal = (new VitroRequest(request)).getPortal();
|
|
||||||
|
|
||||||
request.setAttribute("bodyJsp", Controllers.SEARCH_ERROR_JSP);
|
|
||||||
RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
|
|
||||||
rd.forward(request, response);
|
|
||||||
}
|
|
||||||
private final String defaultSearchField = "ALLTEXT";
|
private final String defaultSearchField = "ALLTEXT";
|
||||||
public static final int MAX_QUERY_LENGTH = 500;
|
public static final int MAX_QUERY_LENGTH = 500;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
<h2>
|
<h2>
|
||||||
Search Results for '${querytext}'
|
Search Results for '${querytext}'
|
||||||
<#if classgroupName?has_content>limited to type '${classgroupName}'</#if>
|
<#if classgroupName?has_content>limited to type '${classGroupName}'</#if>
|
||||||
<#if typeName?has_content>limited to type '${typeName}'</#if>
|
<#if typeName?has_content>limited to type '${typeName}'</#if>
|
||||||
</h2>
|
</h2>
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||||
|
|
||||||
|
<#-- Template for displaying search error message -->
|
||||||
|
|
||||||
|
<#if title??>
|
||||||
|
<h2>${title}</h2>
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<p>${message}</p>
|
Loading…
Add table
Add a link
Reference in a new issue