sortFieldConfiguration.getType());
sortOptions.add(sortField);
}
request.setAttribute("sortOptions", sortOptions);
DiscoverQuery queryArgs = DiscoverUtility.getDiscoverQuery(context,
request, scope, true);
queryArgs.setSpellCheck(discoveryConfiguration.isSpellCheckEnabled());
List<DiscoverySearchFilterFacet> availableFacet = discoveryConfiguration
.getSidebarFacets();
request.setAttribute("facetsConfig",
availableFacet != null ? availableFacet
: new ArrayList<DiscoverySearchFilterFacet>());
int etal = UIUtil.getIntParameter(request, "etal");
if (etal == -1)
{
etal = ConfigurationManager
.getIntProperty("webui.itemlist.author-limit");
}
request.setAttribute("etal", etal);
String query = queryArgs.getQuery();
request.setAttribute("query", query);
request.setAttribute("queryArgs", queryArgs);
List<DiscoverySearchFilter> availableFilters = discoveryConfiguration
.getSearchFilters();
request.setAttribute("availableFilters", availableFilters);
List<String[]> appliedFilters = DiscoverUtility.getFilters(request);
request.setAttribute("appliedFilters", appliedFilters);
List<String> appliedFilterQueries = new ArrayList<String>();
for (String[] filter : appliedFilters)
{
appliedFilterQueries.add(filter[0] + "::" + filter[1] + "::"
+ filter[2]);
}
request.setAttribute("appliedFilterQueries", appliedFilterQueries);
List<DSpaceObject> scopes = new ArrayList<DSpaceObject>();
if (scope == null)
{
Community[] topCommunities;
try
{
topCommunities = Community.findAllTop(context);
}
catch (SQLException e)
{
throw new SearchProcessorException(e.getMessage(), e);
}
for (Community com : topCommunities)
{
scopes.add(com);
}
}
else
{
try
{
DSpaceObject pDso = scope.getParentObject();
while (pDso != null)
{
// add to the available scopes in reverse order
scopes.add(0, pDso);
pDso = pDso.getParentObject();
}
scopes.add(scope);
if (scope instanceof Community)
{
Community[] comms = ((Community) scope).getSubcommunities();
for (Community com : comms)
{
scopes.add(com);
}
Collection[] colls = ((Community) scope).getCollections();
for (Collection col : colls)
{
scopes.add(col);
}
}
}
catch (SQLException e)
{
throw new SearchProcessorException(e.getMessage(), e);
}
}
request.setAttribute("scope", scope);
request.setAttribute("scopes", scopes);
// Perform the search
DiscoverResult qResults = null;
try
{
qResults = SearchUtils.getSearchService().search(context, scope,
queryArgs);
List<Community> resultsListComm = new ArrayList<Community>();
List<Collection> resultsListColl = new ArrayList<Collection>();
List<Item> resultsListItem = new ArrayList<Item>();
for (DSpaceObject dso : qResults.getDspaceObjects())
{
if (dso instanceof Item)
{
resultsListItem.add((Item) dso);
}
else if (dso instanceof Collection)
{
resultsListColl.add((Collection) dso);
}
else if (dso instanceof Community)
{
resultsListComm.add((Community) dso);
}
}
// Make objects from the handles - make arrays, fill them out
resultsCommunities = new Community[resultsListComm.size()];
resultsCollections = new Collection[resultsListColl.size()];
resultsItems = new Item[resultsListItem.size()];
resultsCommunities = resultsListComm.toArray(resultsCommunities);
resultsCollections = resultsListColl.toArray(resultsCollections);
resultsItems = resultsListItem.toArray(resultsItems);
// Log
log.info(LogManager.getHeader(context, "search", "scope=" + scope
+ ",query=\"" + query + "\",results=("
+ resultsCommunities.length + ","
+ resultsCollections.length + "," + resultsItems.length
+ ")"));
// Pass in some page qualities
// total number of pages
long pageTotal = 1 + ((qResults.getTotalSearchResults() - 1) / qResults
.getMaxResults());
// current page being displayed
long pageCurrent = 1 + (qResults.getStart() / qResults
.getMaxResults());
// pageLast = min(pageCurrent+3,pageTotal)
long pageLast = ((pageCurrent + 3) > pageTotal) ? pageTotal
: (pageCurrent + 3);
// pageFirst = max(1,pageCurrent-3)
long pageFirst = ((pageCurrent - 3) > 1) ? (pageCurrent - 3) : 1;
// Pass the results to the display JSP
request.setAttribute("items", resultsItems);
request.setAttribute("communities", resultsCommunities);
request.setAttribute("collections", resultsCollections);
request.setAttribute("pagetotal", new Long(pageTotal));
request.setAttribute("pagecurrent", new Long(pageCurrent));
request.setAttribute("pagelast", new Long(pageLast));
request.setAttribute("pagefirst", new Long(pageFirst));
request.setAttribute("spellcheck", qResults.getSpellCheckQuery());
request.setAttribute("queryresults", qResults);
try
{
if (AuthorizeManager.isAdmin(context))
{
// Set a variable to create admin buttons
request.setAttribute("admin_button", new Boolean(true));
}
}
catch (SQLException e)
{
throw new SearchProcessorException(e.getMessage(), e); }
if ("submit_export_metadata".equals(UIUtil.getSubmitButton(request,
"submit")))
{
exportMetadata(context, response, resultsItems);
}
}
catch (SearchServiceException e)
{
log.error(
LogManager.getHeader(context, "search", "query="
+ queryArgs.getQuery() + ",scope=" + scope
+ ",error=" + e.getMessage()), e);
request.setAttribute("search.error", true);
request.setAttribute("search.error.message", e.getMessage());
}