public String getSearchForm(
@RequestParam(defaultValue = "", required = false) String q,
@RequestParam(defaultValue = "hirubila-nonreglated-", required = false) String collection,
@RequestParam(defaultValue = "1", required = false) Integer page,
Model model, Locale locale) {
SearchForm searchForm = new SearchForm();
searchForm.setCollection(collection);
try {
if (q != null && !("").equals(q)) {
StringTokenizer terms = new StringTokenizer(q.trim());
SearchParamsImpl params = new SearchParamsImpl();
params.addParam(PARAM.CLIENT, gsa_client);
params.addParam(PARAM.SEARCH_URI, this.serviceLocator.getAppConfigurationService().
getGlobalConfiguration().getSearchUri());
params.addParam(PARAM.BASE_COLLECTION_NAME, collection);
params.addParam(PARAM.LANG, locale.getLanguage());
PageManager<ISearchResults> paginator = new PageManager<ISearchResults>();
paginator.setStart((page - 1) * paginator.getOffset());
params.addParam(PARAM.START, String.valueOf(paginator
.getStart()));
this.serviceLocator.getSearchEngine().search(terms, params);
ISearchResults results = this.serviceLocator.getSearchEngine().getSearchResults();
paginator.setCollection((Collection) results);
try {
paginator
.setSize(Long.parseLong(results.getTotalResults()));
model.addAttribute("paginator", paginator);
} catch (Exception e) {
paginator.setSize(0);
}
}
} catch (Exception e) {
LOGGER.severe(StackTraceUtil.getStackTrace(e));
return "common.error";
}
if (q != null && !("").equals(q)) {
searchForm.setQuery(q);
model.addAttribute("search", searchForm);
return "search.results";
} else {
model.addAttribute("search", searchForm);
return "search.form";