}
if (form.getFirstValue("collapseresults") != null) {
collapseResults = Boolean.valueOf(form.getFirstValue("collapseresults"));
}
IteratorSearchResponse searchResult = null;
SearchResponse result = new SearchResponse();
try {
int countRequested = count == null ? HIT_LIMIT : count;
searchResult =
searchByTerms(terms, getRepositoryId(request), from, countRequested, exact, expandVersion,
expandPackaging, expandClassifier, collapseResults);
result.setTooManyResults(searchResult.getTotalHitsCount() > countRequested);
result.setTotalCount(searchResult.getTotalHitsCount());
result.setFrom(from == null ? -1 : from.intValue());
result.setCount(count == null ? -1 : count);
result.setData(new ArrayList<NexusArtifact>(ai2NaColl(request, searchResult.getResults())));
// if we had collapseResults ON, and the totalHits are larger than actual (filtered) results,
// and
// the actual result count is below COLLAPSE_OVERRIDE_TRESHOLD,
// and full result set is smaller than HIT_LIMIT
// then repeat without collapse
if (collapseResults && result.getData().size() < searchResult.getTotalHitsCount()
&& result.getData().size() < COLLAPSE_OVERRIDE_TRESHOLD && searchResult.getTotalHitsCount() < HIT_LIMIT) {
collapseResults = false;
}
}
catch (NoSuchRepositoryException e) {
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Repository with ID='"
+ getRepositoryId(request) + "' does not exists!", e);
}
catch (IOException e) {
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage(), e);
}
finally {
if (searchResult != null) {
try {
searchResult.close();
}
catch (IOException e) {
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage(), e);
}
}