use of uk.nhs.digital.intranet.enums.SearchArea in project hippo by NHS-digital-website.
the class SearchPageComponent method searchContent.
private void searchContent(HstRequest request, List<SearchResultTab> searchResultTabs) {
final SearchArea searchArea = getAreaOption(request);
final String searchQuery = getSearchQuery(request, true);
if (searchArea != SearchArea.PEOPLE) {
final Pageable<HippoBean> bloomreachResults = bloomreachSearchProvider.getBloomreachResults(searchQuery, getComponentInfo(request).getPageSize(), getCurrentPage(request), searchArea);
request.setAttribute(REQUEST_ATTR_PAGEABLE, bloomreachResults);
if (searchArea != SearchArea.ALL) {
searchResultTabs.add(new SearchResultTab(searchArea, Math.toIntExact(bloomreachResults.getTotal())));
}
}
SearchArea.getDocumentSearchAreasWithout(searchArea).forEach(unselectedSearchArea -> searchResultTabs.add(new SearchResultTab(unselectedSearchArea, bloomreachSearchProvider.getBloomreachResultsCount(searchQuery, unselectedSearchArea))));
}
use of uk.nhs.digital.intranet.enums.SearchArea in project hippo by NHS-digital-website.
the class SearchPageComponent method searchPeople.
private void searchPeople(HstRequest request, List<SearchResultTab> searchResultTabs) {
final String accessToken = (String) RequestContextProvider.get().getAttribute(Constants.ACCESS_TOKEN_PROPERTY_NAME);
final SearchArea area = getAreaOption(request);
final String searchQuery = getSearchQuery(request, false);
final int peopleLimit = getComponentInfo(request).getPeopleLimit();
int numberOfResults;
if (!StringUtils.hasText(accessToken)) {
numberOfResults = 0;
request.setAttribute(REQUEST_ATTR_ACCESS_TOKEN_REQUIRED, true);
} else if (!StringUtils.hasText(searchQuery)) {
numberOfResults = 0;
request.setAttribute(REQUEST_ATTR_MISSING_TERM_ERROR_MESSAGE, true);
} else {
try {
List<Person> people = graphProvider.getPeople(searchQuery);
int peopleCount = people.size();
if (SearchArea.ALL.equals(area) && peopleCount > peopleLimit) {
people = people.subList(0, peopleLimit);
request.setAttribute(REQUEST_ATTR_MORE_PEOPLE, true);
}
numberOfResults = peopleCount;
request.setAttribute(REQUEST_ATTR_PEOPLE_RESULTS, people);
} catch (ProviderCommunicationException e) {
numberOfResults = 0;
request.setAttribute(REQUEST_ATTR_API_ERROR_MESSAGE, true);
}
}
searchResultTabs.add(new SearchResultTab(SearchArea.PEOPLE, numberOfResults));
}
Aggregations