Search in sources :

Example 6 with ResultTypeIndexSearchResponseDto

use of org.finra.herd.model.dto.ResultTypeIndexSearchResponseDto in project herd by FINRAOS.

the class ElasticsearchHelper method getFacetsResponse.

/**
 * get the facets in the response
 *
 * @param elasticsearchResponseDto elastic search response dto
 * @param bdefActiveIndex the name of the active index for business object definitions
 * @param tagActiveIndex the name os the active index for tags
 *
 * @return facets in the response dto
 */
public List<Facet> getFacetsResponse(ElasticsearchResponseDto elasticsearchResponseDto, final String bdefActiveIndex, final String tagActiveIndex) {
    List<Facet> facets = new ArrayList<>();
    List<Facet> tagTypeFacets;
    if (elasticsearchResponseDto.getNestTagTypeIndexSearchResponseDtos() != null) {
        tagTypeFacets = new ArrayList<>();
        // construct a list of facet information
        for (TagTypeIndexSearchResponseDto tagTypeIndexSearchResponseDto : elasticsearchResponseDto.getNestTagTypeIndexSearchResponseDtos()) {
            tagTypeFacets.add(createTagTypeFacet(tagTypeIndexSearchResponseDto));
        }
        facets.addAll(tagTypeFacets);
    }
    if (elasticsearchResponseDto.getTagTypeIndexSearchResponseDtos() != null) {
        for (TagTypeIndexSearchResponseDto tagTypeIndexDto : elasticsearchResponseDto.getTagTypeIndexSearchResponseDtos()) {
            boolean foundMatchingTagType = false;
            for (Facet tagFacet : facets) {
                if (tagFacet.getFacetId().equals(tagTypeIndexDto.getCode())) {
                    foundMatchingTagType = true;
                    boolean foundMatchingTagCode = false;
                    for (TagIndexSearchResponseDto tagIndexDto : tagTypeIndexDto.getTagIndexSearchResponseDtos()) {
                        for (Facet nestedTagIndexDto : tagFacet.getFacets()) {
                            if (tagIndexDto.getTagCode().equals(nestedTagIndexDto.getFacetId())) {
                                foundMatchingTagCode = true;
                            }
                        }
                        if (!foundMatchingTagCode) {
                            tagFacet.getFacets().add(new Facet(tagIndexDto.getTagDisplayName(), tagIndexDto.getCount(), FacetTypeEnum.TAG.value(), tagIndexDto.getTagCode(), null));
                        }
                    }
                }
            }
            if (!foundMatchingTagType) {
                facets.add(createTagTypeFacet(tagTypeIndexDto));
            }
        }
    }
    if (elasticsearchResponseDto.getResultTypeIndexSearchResponseDtos() != null) {
        List<Facet> resultTypeFacets = new ArrayList<>();
        // construct a list of facet information
        for (ResultTypeIndexSearchResponseDto resultTypeIndexSearchResponseDto : elasticsearchResponseDto.getResultTypeIndexSearchResponseDtos()) {
            String facetId = getSearchIndexType(resultTypeIndexSearchResponseDto.getResultTypeDisplayName(), bdefActiveIndex, tagActiveIndex);
            Facet resultTypeFacet = new Facet(facetId, resultTypeIndexSearchResponseDto.getCount(), FacetTypeEnum.RESULT_TYPE.value(), facetId, null);
            resultTypeFacets.add(resultTypeFacet);
        }
        facets.addAll(resultTypeFacets);
    }
    return facets;
}
Also used : TagIndexSearchResponseDto(org.finra.herd.model.dto.TagIndexSearchResponseDto) ArrayList(java.util.ArrayList) TagTypeIndexSearchResponseDto(org.finra.herd.model.dto.TagTypeIndexSearchResponseDto) ResultTypeIndexSearchResponseDto(org.finra.herd.model.dto.ResultTypeIndexSearchResponseDto) Facet(org.finra.herd.model.api.xml.Facet)

Example 7 with ResultTypeIndexSearchResponseDto

use of org.finra.herd.model.dto.ResultTypeIndexSearchResponseDto in project herd by FINRAOS.

the class ElasticsearchHelper method getResultTypeIndexSearchResponseDto.

/**
 * Creates result type facet response dto
 *
 * @param searchResponse search response
 *
 * @return result type facet response dto list
 */
public List<ResultTypeIndexSearchResponseDto> getResultTypeIndexSearchResponseDto(SearchResponse searchResponse) {
    List<ResultTypeIndexSearchResponseDto> list = new ArrayList<>();
    Terms aggregation = getAggregation(searchResponse, RESULT_TYPE_AGGS);
    for (Terms.Bucket resultTypeEntry : aggregation.getBuckets()) {
        ResultTypeIndexSearchResponseDto dto = new ResultTypeIndexSearchResponseDto();
        dto.setResultTypeCode(resultTypeEntry.getKeyAsString());
        dto.setResultTypeDisplayName(resultTypeEntry.getKeyAsString());
        dto.setCount(resultTypeEntry.getDocCount());
        list.add(dto);
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) ResultTypeIndexSearchResponseDto(org.finra.herd.model.dto.ResultTypeIndexSearchResponseDto)

Aggregations

ArrayList (java.util.ArrayList)7 ResultTypeIndexSearchResponseDto (org.finra.herd.model.dto.ResultTypeIndexSearchResponseDto)7 MetricAggregation (io.searchbox.core.search.aggregation.MetricAggregation)3 TermsAggregation (io.searchbox.core.search.aggregation.TermsAggregation)3 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)3 TagIndexSearchResponseDto (org.finra.herd.model.dto.TagIndexSearchResponseDto)3 TagTypeIndexSearchResponseDto (org.finra.herd.model.dto.TagTypeIndexSearchResponseDto)3 Test (org.junit.Test)3 SearchResult (io.searchbox.core.SearchResult)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)2 Facet (org.finra.herd.model.api.xml.Facet)2 ElasticsearchResponseDto (org.finra.herd.model.dto.ElasticsearchResponseDto)2 Gson (com.google.gson.Gson)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1