Search in sources :

Example 1 with SearchArea

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))));
}
Also used : HippoBean(org.hippoecm.hst.content.beans.standard.HippoBean) SearchArea(uk.nhs.digital.intranet.enums.SearchArea) SearchResultTab(uk.nhs.digital.intranet.model.SearchResultTab)

Example 2 with SearchArea

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));
}
Also used : ProviderCommunicationException(uk.nhs.digital.intranet.model.exception.ProviderCommunicationException) SearchArea(uk.nhs.digital.intranet.enums.SearchArea) SearchResultTab(uk.nhs.digital.intranet.model.SearchResultTab)

Aggregations

SearchArea (uk.nhs.digital.intranet.enums.SearchArea)2 SearchResultTab (uk.nhs.digital.intranet.model.SearchResultTab)2 HippoBean (org.hippoecm.hst.content.beans.standard.HippoBean)1 ProviderCommunicationException (uk.nhs.digital.intranet.model.exception.ProviderCommunicationException)1