RestQuery query) throws SearchException {
// make the search engine
ASearchEngine engine = null;
SearchCriteria criteria = this.toSearchCriteria(request, context, query);
SearchResult result = new SearchResult();
String rid = Val.chkStr(query.getRepositoryId());
RestQueryServlet.ResponseFormat format = getResponseFormat(request, query);
boolean isJavascriptEnabled =
Val.chkBool(request.getParameter("isJavascriptEnabled"), false);
if (format.toString().toLowerCase().startsWith("searchpage")
|| isJavascriptEnabled == true) {
if (format.toString().toLowerCase().startsWith("searchpage")) {
@SuppressWarnings("unchecked")
Map<String, String> extraArgs = (Map<String, String>) context
.getObjectMap().get(EXTRA_REST_ARGS_MAP);
if (extraArgs != null) {
if (extraArgs.get(PARAM_KEY_SHOW_RELATIVE_URLS) == null) {
extraArgs.put(PARAM_KEY_SHOW_RELATIVE_URLS, "true");
}
extraArgs.put(PARAM_KEY_IS_JSFREQUEST, "true");
}
}
context.setViewerExecutesJavascript(true);
} else {
context.setViewerExecutesJavascript(false);
}
ResourceLinkBuilder rBuild = ResourceLinkBuilder.newBuilder(context,
request, messageBroker);
// handle a request against the local repository
if ((rid.length() == 0) || rid.equalsIgnoreCase("local")) {
// generate the CSW request string
String cswRequest = "";
try {
GetRecordsGenerator grg = new GetRecordsGenerator(context);
cswRequest = grg.generateCswRequest(query);
} catch (Exception e) {
throw new SearchException(e);
}
// execute the query
engine = SearchEngineFactory.createSearchEngine(criteria, result, context, messageBroker);
SearchEngineCSW csw = (SearchEngineCSW) engine;
csw.setResourceLinkBuilder(rBuild);
csw.doSearch(cswRequest);
// handle a request against a remote repository
} else {
// create the criteria, execute the query
int iSearchTime = Val.chkInt(request.getParameter("maxSearchTimeMilliSec"), -1);
engine = SearchEngineFactory.createSearchEngine(criteria, result, context, rid, messageBroker);
engine.setResourceLinkBuilder(rBuild);
if (iSearchTime > 0) {
engine.setConnectionTimeoutMs(iSearchTime);
engine.setResponseTimeout(iSearchTime);
}
engine.doSearch();
}
// set the OpenSearch properties
String basePath = RequestContext.resolveBaseContextPath(request);
String osURL = basePath + "/openSearchDescription";
//String osURL = request.getRequestURL().toString();
//osURL = osURL.replaceAll("/rest/find/document","/openSearchDescription");
OpenSearchProperties osProps = new OpenSearchProperties();
osProps.setShortName(messageBroker.retrieveMessage("catalog.openSearch.shortName"));
osProps.setDescriptionURL(osURL);
osProps.setNumberOfHits(result.getMaxQueryHits());
osProps.setStartRecord(query.getFilter().getStartRecord());
osProps.setRecordsPerPage(query.getFilter().getMaxRecords());
result.getRecords().setOpenSearchProperties(osProps);
return result;
}