Search in sources :

Example 1 with TagIndexSearchResponseDto

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

the class ElasticSearchHelperTest method testGetFacetsResponseIncludingTagWithNoAssociatedBdefsNewTagType.

@Test
public void testGetFacetsResponseIncludingTagWithNoAssociatedBdefsNewTagType() {
    ElasticsearchResponseDto elasticsearchResponseDto = new ElasticsearchResponseDto();
    List<TagTypeIndexSearchResponseDto> nestTagTypeIndexSearchResponseDtos = new ArrayList<>();
    TagTypeIndexSearchResponseDto tagType1 = new TagTypeIndexSearchResponseDto(TAG_TYPE_CODE, null, TAG_TYPE_DISPLAY_NAME);
    TagTypeIndexSearchResponseDto tagType2 = new TagTypeIndexSearchResponseDto(TAG_TYPE_CODE_2, Collections.singletonList(new TagIndexSearchResponseDto(TAG_CODE, 1, TAG_CODE_DISPLAY_NAME)), TAG_TYPE_DISPLAY_NAME_2);
    nestTagTypeIndexSearchResponseDtos.add(tagType1);
    nestTagTypeIndexSearchResponseDtos.add(tagType2);
    elasticsearchResponseDto.setNestTagTypeIndexSearchResponseDtos(nestTagTypeIndexSearchResponseDtos);
    TagTypeIndexSearchResponseDto tagType3 = new TagTypeIndexSearchResponseDto(TAG_TYPE_CODE_3, Collections.singletonList(new TagIndexSearchResponseDto(TAG_CODE_2, 1, TAG_CODE_DISPLAY_NAME_2)), TAG_TYPE_DISPLAY_NAME_3);
    List<TagTypeIndexSearchResponseDto> tagTypeIndexSearchResponseDtos = new ArrayList<>();
    tagTypeIndexSearchResponseDtos.add(tagType3);
    elasticsearchResponseDto.setTagTypeIndexSearchResponseDtos(tagTypeIndexSearchResponseDtos);
    List<Facet> facets = elasticsearchHelper.getFacetsResponse(elasticsearchResponseDto, BUSINESS_OBJECT_DEFINITION_SEARCH_INDEX_NAME, TAG_SEARCH_INDEX_NAME);
    List<Facet> expectedFacets = new ArrayList<>();
    expectedFacets.add(new Facet(TAG_TYPE_DISPLAY_NAME, null, FacetTypeEnum.TAG_TYPE.value(), TAG_TYPE_CODE, new ArrayList<>()));
    List<Facet> tagFacet = new ArrayList<>();
    tagFacet.add(new Facet(TAG_CODE_DISPLAY_NAME, 1L, FacetTypeEnum.TAG.value(), TAG_CODE, null));
    List<Facet> newTagFacet = new ArrayList<>();
    newTagFacet.add(new Facet(TAG_CODE_DISPLAY_NAME_2, 1L, FacetTypeEnum.TAG.value(), TAG_CODE_2, null));
    expectedFacets.add(new Facet(TAG_TYPE_DISPLAY_NAME_2, null, FacetTypeEnum.TAG_TYPE.value(), TAG_TYPE_CODE_2, tagFacet));
    expectedFacets.add(new Facet(TAG_TYPE_DISPLAY_NAME_3, null, FacetTypeEnum.TAG_TYPE.value(), TAG_TYPE_CODE_3, newTagFacet));
    assertEquals(expectedFacets, facets);
}
Also used : TagIndexSearchResponseDto(org.finra.herd.model.dto.TagIndexSearchResponseDto) TagTypeIndexSearchResponseDto(org.finra.herd.model.dto.TagTypeIndexSearchResponseDto) ArrayList(java.util.ArrayList) ElasticsearchResponseDto(org.finra.herd.model.dto.ElasticsearchResponseDto) Facet(org.finra.herd.model.api.xml.Facet) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 2 with TagIndexSearchResponseDto

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

the class ElasticSearchHelperTest method testGetFacetsResponse.

@Test
public void testGetFacetsResponse() {
    ElasticsearchResponseDto elasticsearchResponseDto = new ElasticsearchResponseDto();
    List<TagTypeIndexSearchResponseDto> nestTagTypeIndexSearchResponseDtos = new ArrayList<>();
    TagTypeIndexSearchResponseDto tagType1 = new TagTypeIndexSearchResponseDto(TAG_TYPE_CODE, null, TAG_TYPE_DISPLAY_NAME);
    TagTypeIndexSearchResponseDto tagType2 = new TagTypeIndexSearchResponseDto(TAG_TYPE_CODE_2, Collections.singletonList(new TagIndexSearchResponseDto(TAG_CODE, 1, TAG_CODE_DISPLAY_NAME)), TAG_TYPE_DISPLAY_NAME_2);
    nestTagTypeIndexSearchResponseDtos.add(tagType1);
    nestTagTypeIndexSearchResponseDtos.add(tagType2);
    elasticsearchResponseDto.setNestTagTypeIndexSearchResponseDtos(nestTagTypeIndexSearchResponseDtos);
    List<ResultTypeIndexSearchResponseDto> resultTypeIndexSearchResponseDtos = new ArrayList<>();
    resultTypeIndexSearchResponseDtos.add(new ResultTypeIndexSearchResponseDto(TAG_CODE, TAG_COUNT, TAG_SEARCH_INDEX_NAME));
    elasticsearchResponseDto.setResultTypeIndexSearchResponseDtos(resultTypeIndexSearchResponseDtos);
    List<Facet> facets = elasticsearchHelper.getFacetsResponse(elasticsearchResponseDto, BUSINESS_OBJECT_DEFINITION_SEARCH_INDEX_NAME, TAG_SEARCH_INDEX_NAME);
    List<Facet> expectedFacets = new ArrayList<>();
    expectedFacets.add(new Facet(TAG_TYPE_DISPLAY_NAME, null, FacetTypeEnum.TAG_TYPE.value(), TAG_TYPE_CODE, new ArrayList<>()));
    List<Facet> tagFacet = new ArrayList<>();
    tagFacet.add(new Facet(TAG_CODE_DISPLAY_NAME, 1L, FacetTypeEnum.TAG.value(), TAG_CODE, null));
    expectedFacets.add(new Facet(TAG_TYPE_DISPLAY_NAME_2, null, FacetTypeEnum.TAG_TYPE.value(), TAG_TYPE_CODE_2, tagFacet));
    expectedFacets.add(new Facet(SearchIndexTypeEntity.SearchIndexTypes.TAG.name(), 120L, FacetTypeEnum.RESULT_TYPE.value(), SearchIndexTypeEntity.SearchIndexTypes.TAG.name(), null));
    assertEquals(expectedFacets, facets);
}
Also used : TagIndexSearchResponseDto(org.finra.herd.model.dto.TagIndexSearchResponseDto) TagTypeIndexSearchResponseDto(org.finra.herd.model.dto.TagTypeIndexSearchResponseDto) ArrayList(java.util.ArrayList) ResultTypeIndexSearchResponseDto(org.finra.herd.model.dto.ResultTypeIndexSearchResponseDto) ElasticsearchResponseDto(org.finra.herd.model.dto.ElasticsearchResponseDto) Facet(org.finra.herd.model.api.xml.Facet) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 3 with TagIndexSearchResponseDto

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

the class ElasticSearchHelperTest method testGetFacetsResponseIncludingTagWithNoAssociatedBdefs.

@Test
public void testGetFacetsResponseIncludingTagWithNoAssociatedBdefs() {
    ElasticsearchResponseDto elasticsearchResponseDto = new ElasticsearchResponseDto();
    List<TagTypeIndexSearchResponseDto> nestTagTypeIndexSearchResponseDtos = new ArrayList<>();
    TagTypeIndexSearchResponseDto tagType1 = new TagTypeIndexSearchResponseDto(TAG_TYPE_CODE, null, TAG_TYPE_DISPLAY_NAME);
    TagTypeIndexSearchResponseDto tagType2 = new TagTypeIndexSearchResponseDto(TAG_TYPE_CODE_2, Collections.singletonList(new TagIndexSearchResponseDto(TAG_CODE, 1, TAG_CODE_DISPLAY_NAME)), TAG_TYPE_DISPLAY_NAME_2);
    nestTagTypeIndexSearchResponseDtos.add(tagType1);
    nestTagTypeIndexSearchResponseDtos.add(tagType2);
    elasticsearchResponseDto.setNestTagTypeIndexSearchResponseDtos(nestTagTypeIndexSearchResponseDtos);
    TagTypeIndexSearchResponseDto tagType3 = new TagTypeIndexSearchResponseDto(TAG_TYPE_CODE_2, Collections.singletonList(new TagIndexSearchResponseDto(TAG_CODE_2, 1, TAG_CODE_DISPLAY_NAME_2)), TAG_TYPE_DISPLAY_NAME_2);
    List<TagTypeIndexSearchResponseDto> tagTypeIndexSearchResponseDtos = new ArrayList<>();
    tagTypeIndexSearchResponseDtos.add(tagType3);
    elasticsearchResponseDto.setTagTypeIndexSearchResponseDtos(tagTypeIndexSearchResponseDtos);
    List<Facet> facets = elasticsearchHelper.getFacetsResponse(elasticsearchResponseDto, BUSINESS_OBJECT_DEFINITION_SEARCH_INDEX_NAME, TAG_SEARCH_INDEX_NAME);
    List<Facet> expectedFacets = new ArrayList<>();
    expectedFacets.add(new Facet(TAG_TYPE_DISPLAY_NAME, null, FacetTypeEnum.TAG_TYPE.value(), TAG_TYPE_CODE, new ArrayList<>()));
    List<Facet> tagFacet = new ArrayList<>();
    tagFacet.add(new Facet(TAG_CODE_DISPLAY_NAME, 1L, FacetTypeEnum.TAG.value(), TAG_CODE, null));
    tagFacet.add(new Facet(TAG_CODE_DISPLAY_NAME_2, 1L, FacetTypeEnum.TAG.value(), TAG_CODE_2, null));
    expectedFacets.add(new Facet(TAG_TYPE_DISPLAY_NAME_2, null, FacetTypeEnum.TAG_TYPE.value(), TAG_TYPE_CODE_2, tagFacet));
    assertEquals(expectedFacets, facets);
}
Also used : TagIndexSearchResponseDto(org.finra.herd.model.dto.TagIndexSearchResponseDto) TagTypeIndexSearchResponseDto(org.finra.herd.model.dto.TagTypeIndexSearchResponseDto) ArrayList(java.util.ArrayList) ElasticsearchResponseDto(org.finra.herd.model.dto.ElasticsearchResponseDto) Facet(org.finra.herd.model.api.xml.Facet) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 4 with TagIndexSearchResponseDto

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

the class IndexSearchDaoTest method testIndexSearch.

private void testIndexSearch(Set<String> fields, Set<String> match, List<IndexSearchFilter> searchFilters, List<String> facetList, boolean isHitHighlightingEnabled, boolean testExceptions, boolean setInvalidSearchResultIndexName, boolean isColumnFields) throws IOException {
    // Build the mocks
    SearchRequestBuilder searchRequestBuilder = mock(SearchRequestBuilder.class);
    SearchRequestBuilder searchRequestBuilderWithSource = mock(SearchRequestBuilder.class);
    SearchRequestBuilder searchRequestBuilderWithSize = mock(SearchRequestBuilder.class);
    SearchRequestBuilder searchRequestBuilderWithSorting = mock(SearchRequestBuilder.class);
    SearchRequestBuilder searchRequestBuilderWithHighlighting = mock(SearchRequestBuilder.class);
    SearchResponse searchResponse = mock(SearchResponse.class);
    SearchHits searchHits = mock(SearchHits.class);
    SearchHit searchHit1 = mock(SearchHit.class);
    SearchHit searchHit2 = mock(SearchHit.class);
    SearchShardTarget searchShardTarget1 = mock(SearchShardTarget.class);
    SearchShardTarget searchShardTarget2 = mock(SearchShardTarget.class);
    SearchHit[] searchHitArray = new SearchHit[2];
    searchHitArray[0] = searchHit1;
    searchHitArray[1] = searchHit2;
    HighlightField highlightField = mock(HighlightField.class);
    when(highlightField.getName()).thenReturn("displayName");
    Text[] value = { new Text("match <hlt>fragment</hlt class=\"highlight\">"), new Text("<hlt class=\"highlight\">match</hlt>") };
    when(highlightField.getFragments()).thenReturn(value);
    @SuppressWarnings("unchecked") ListenableActionFuture<SearchResponse> listenableActionFuture = mock(ListenableActionFuture.class);
    final String highlightFieldsConfigValue = "{\"highlightFields\":[{\"fieldName\":\"displayName\",\"fragmentSize\":100,\"matchedFields\":[\"displayName\",\"displayName.stemmed\",\"displayName.ngrams\"],\"numOfFragments\":5}]}";
    final String highlightFieldsColumnMatchConfigValue = "{\"highlightFields\":[{\"fieldName\":\"columnName\",\"fragmentSize\":100,\"matchedFields\":[\"columnName\",\"columnName.stemmed\",\"columnName.ngrams\"],\"numOfFragments\":5}]}";
    // Mock the call to external methods
    when(configurationHelper.getProperty(ConfigurationValue.TAG_SHORT_DESCRIPTION_LENGTH, Integer.class)).thenReturn(300);
    when(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class)).thenReturn(300);
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_SEARCHABLE_FIELDS_NGRAMS)).thenReturn("{\"displayName\":\"1.0\"}");
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_SEARCHABLE_FIELDS_STEMMED)).thenReturn("{\"displayName\":\"1.0\"}");
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_SEARCHABLE_FIELDS_SHINGLES)).thenReturn("{\"displayName\":\"1.0\"}");
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_HIGHLIGHT_PRETAGS)).thenReturn("<hlt class=\"highlight\">");
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_HIGHLIGHT_POSTTAGS)).thenReturn("</hlt>");
    if (match != null && match.contains(MATCH_COLUMN)) {
        when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_COLUMN_MATCH_HIGHLIGHT_FIELDS)).thenReturn(highlightFieldsColumnMatchConfigValue);
    } else {
        when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_HIGHLIGHT_FIELDS)).thenReturn(highlightFieldsConfigValue);
    }
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BEST_FIELDS_QUERY_BOOST, Float.class)).thenReturn(1f);
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_PHRASE_PREFIX_QUERY_BOOST, Float.class)).thenReturn(1f);
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_PHRASE_QUERY_BOOST, Float.class)).thenReturn(1f);
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_PHRASE_QUERY_SLOP, Integer.class)).thenReturn(5);
    Map<String, String> fieldsBoostMap = new HashMap<>();
    fieldsBoostMap.put("displayName", "1.0");
    if (isColumnFields) {
        fieldsBoostMap.put(COLUMNS_NAME_FIELD, "1.0");
        fieldsBoostMap.put(SCHEMA_COLUMNS_NAME_FIELD, "1.0");
    }
    if (testExceptions) {
        when(jsonHelper.unmarshallJsonToObject(Map.class, "{\"displayName\":\"1.0\"}")).thenThrow(new IOException());
    } else {
        when(jsonHelper.unmarshallJsonToObject(Map.class, "{\"displayName\":\"1.0\"}")).thenReturn(fieldsBoostMap);
    }
    IndexSearchHighlightField indexSearchHighlightField = new IndexSearchHighlightField("displayName", 100, Arrays.asList("displayName", "displayName.stemmed", "displayName.ngrams"), 5);
    IndexSearchHighlightFields highlightFields = new IndexSearchHighlightFields(Collections.singletonList(indexSearchHighlightField));
    IndexSearchHighlightField indexSearchHighlightFieldColumnOnly = new IndexSearchHighlightField("columnName", 100, Arrays.asList("columnName", "columnName.stemmed", "columnName.ngrams"), 5);
    IndexSearchHighlightFields highlightFieldsColumnOnly = new IndexSearchHighlightFields(Collections.singletonList(indexSearchHighlightFieldColumnOnly));
    if (testExceptions) {
        when(jsonHelper.unmarshallJsonToObject(IndexSearchHighlightFields.class, highlightFieldsConfigValue)).thenThrow(new IOException());
    } else {
        if (match != null && match.contains(MATCH_COLUMN)) {
            when(jsonHelper.unmarshallJsonToObject(IndexSearchHighlightFields.class, highlightFieldsColumnMatchConfigValue)).thenReturn(highlightFieldsColumnOnly);
        } else {
            when(jsonHelper.unmarshallJsonToObject(IndexSearchHighlightFields.class, highlightFieldsConfigValue)).thenReturn(highlightFields);
        }
    }
    when(searchRequestBuilder.setSource(any(SearchSourceBuilder.class))).thenReturn(searchRequestBuilderWithSource);
    when(searchRequestBuilderWithSource.setSize(SEARCH_RESULT_SIZE)).thenReturn(searchRequestBuilderWithSize);
    when(searchRequestBuilderWithSize.addSort(any(SortBuilder.class))).thenReturn(searchRequestBuilderWithSorting);
    when(searchRequestBuilderWithSorting.highlighter(any(HighlightBuilder.class))).thenReturn(searchRequestBuilderWithHighlighting);
    when(searchRequestBuilder.execute()).thenReturn(listenableActionFuture);
    when(listenableActionFuture.actionGet()).thenReturn(searchResponse);
    when(searchResponse.getHits()).thenReturn(searchHits);
    when(searchHits.hits()).thenReturn(searchHitArray);
    Map<String, Object> sourceMap1 = new HashMap<>();
    Map<String, Object> tagTypeMap = new HashMap<>();
    tagTypeMap.put(CODE, TAG_TYPE_CODE);
    sourceMap1.put(TAG_TYPE, tagTypeMap);
    when(searchHit1.sourceAsMap()).thenReturn(sourceMap1);
    Map<String, Object> sourceMap2 = new HashMap<>();
    Map<String, Object> businessObjectDefinitionMap = new HashMap<>();
    businessObjectDefinitionMap.put(CODE, NAMESPACE_CODE);
    sourceMap2.put(NAMESPACE, businessObjectDefinitionMap);
    when(searchHit2.sourceAsMap()).thenReturn(sourceMap2);
    when(searchHit1.getShard()).thenReturn(searchShardTarget1);
    when(searchHit2.getShard()).thenReturn(searchShardTarget2);
    when(searchShardTarget1.getIndex()).thenReturn(TAG_SEARCH_INDEX_NAME);
    when(searchShardTarget2.getIndex()).thenReturn(BUSINESS_OBJECT_DEFINITION_SEARCH_INDEX_NAME);
    when(searchHits.getTotalHits()).thenReturn(200L);
    Map<String, HighlightField> highlightFieldMap = new HashMap<>();
    highlightFieldMap.put("displayName", highlightField);
    when(searchHit1.getHighlightFields()).thenReturn(highlightFieldMap);
    when(searchHit2.getHighlightFields()).thenReturn(highlightFieldMap);
    // Create index search request
    final IndexSearchRequest indexSearchRequest = new IndexSearchRequest(SEARCH_TERM, searchFilters, facetList, isHitHighlightingEnabled);
    List<TagTypeIndexSearchResponseDto> tagTypeIndexSearchResponseDtos = Collections.singletonList(new TagTypeIndexSearchResponseDto("code", Collections.singletonList(new TagIndexSearchResponseDto("tag1", 1, null)), null));
    List<ResultTypeIndexSearchResponseDto> resultTypeIndexSearchResponseDto = Collections.singletonList(new ResultTypeIndexSearchResponseDto("type", 1, null));
    when(elasticsearchHelper.getNestedTagTagIndexSearchResponseDto(searchResponse)).thenReturn(tagTypeIndexSearchResponseDtos);
    when(elasticsearchHelper.getResultTypeIndexSearchResponseDto(searchResponse)).thenReturn(resultTypeIndexSearchResponseDto);
    when(elasticsearchHelper.getFacetsResponse(any(ElasticsearchResponseDto.class), eq(BUSINESS_OBJECT_DEFINITION_SEARCH_INDEX_NAME), eq(TAG_SEARCH_INDEX_NAME))).thenCallRealMethod();
    when(elasticsearchHelper.addIndexSearchFilterBooleanClause(any(), any(), any())).thenCallRealMethod();
    when(elasticsearchHelper.addFacetFieldAggregations(any(), any(SearchRequestBuilder.class))).thenReturn(searchRequestBuilder);
    when(herdSearchQueryHelper.determineNegationTermsPresent(any(IndexSearchRequest.class))).thenCallRealMethod();
    when(herdSearchQueryHelper.extractNegationTerms(any(IndexSearchRequest.class))).thenCallRealMethod();
    when(herdSearchQueryHelper.extractSearchPhrase(any(IndexSearchRequest.class))).thenCallRealMethod();
    SearchResult searchResult = mock(SearchResult.class);
    when(jestClientHelper.searchExecute(any())).thenReturn(searchResult);
    List<SearchResult.Hit<Map, Void>> searchHitList = new ArrayList<>();
    Gson gson = new Gson();
    Map<String, Object> map = new HashMap<>();
    map.put(DISPLAY_NAME_SOURCE, "Display Name");
    Map<String, Object> codeMap = new HashMap<>();
    codeMap.put(CODE, "Code");
    map.put(TAG_TYPE, codeMap);
    map.put(NAMESPACE, codeMap);
    JsonElement element = gson.toJsonTree(map);
    List<String> highlightList = new ArrayList<>();
    highlightList.add("Highlight 1");
    Map<String, List<String>> highlightMap = new HashMap<>();
    highlightMap.put("field", highlightList);
    SearchResult.Hit<Map, Void> hit1 = new SearchResult(gson).new Hit(HashMap.class, element, HashMap.class, null, highlightMap, null, setInvalidSearchResultIndexName ? INVALID_VALUE : TAG_SEARCH_INDEX_NAME, TAG_SEARCH_INDEX_NAME, "type", 1.0);
    SearchResult.Hit<Map, Void> hit2 = new SearchResult(gson).new Hit(HashMap.class, element, HashMap.class, null, highlightMap, null, BUSINESS_OBJECT_DEFINITION_SEARCH_INDEX_NAME, BUSINESS_OBJECT_DEFINITION_SEARCH_INDEX_NAME, "type", 2.0);
    searchHitList.add(hit1);
    searchHitList.add(hit2);
    when(searchResult.getHits(Map.class)).thenReturn(searchHitList);
    when(searchResult.getTotal()).thenReturn(200L);
    MetricAggregation metricAggregation = mock(MetricAggregation.class);
    TermsAggregation termsAggregation = mock(TermsAggregation.class);
    when(searchResult.getAggregations()).thenReturn(metricAggregation);
    when(metricAggregation.getTermsAggregation(TAG_TYPE_FACET_AGGS)).thenReturn(termsAggregation);
    List<TermsAggregation.Entry> buckets = new ArrayList<>();
    TermsAggregation.Entry entry1 = mock(TermsAggregation.Entry.class);
    TermsAggregation.Entry entry2 = mock(TermsAggregation.Entry.class);
    buckets.add(entry1);
    buckets.add(entry2);
    when(termsAggregation.getBuckets()).thenReturn(buckets);
    // Call the method under test
    IndexSearchResponse indexSearchResponse = indexSearchDao.indexSearch(indexSearchRequest, fields, match, BUSINESS_OBJECT_DEFINITION_SEARCH_INDEX_NAME, TAG_SEARCH_INDEX_NAME);
    List<IndexSearchResult> indexSearchResults = indexSearchResponse.getIndexSearchResults();
    assertThat("Index search results list is null.", indexSearchResults, not(nullValue()));
    assertThat(indexSearchResponse.getTotalIndexSearchResults(), is(200L));
    // Verify external method calls.
    verify(herdSearchQueryHelper).determineNegationTermsPresent(indexSearchRequest);
    verify(herdSearchQueryHelper).extractNegationTerms(indexSearchRequest);
    verify(herdSearchQueryHelper).extractSearchPhrase(indexSearchRequest);
    verify(configurationHelper).getProperty(ConfigurationValue.TAG_SHORT_DESCRIPTION_LENGTH, Integer.class);
    verify(configurationHelper).getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class);
    verify(configurationHelper, times(3)).getProperty(ConfigurationValue.ELASTICSEARCH_SEARCHABLE_FIELDS_STEMMED);
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_SEARCHABLE_FIELDS_NGRAMS);
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_SEARCHABLE_FIELDS_SHINGLES);
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_PHRASE_PREFIX_QUERY_BOOST, Float.class);
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BEST_FIELDS_QUERY_BOOST, Float.class);
    verify(configurationHelper, times(2)).getProperty(ConfigurationValue.ELASTICSEARCH_PHRASE_QUERY_BOOST, Float.class);
    verify(configurationHelper, times(5)).getProperty(ConfigurationValue.ELASTICSEARCH_PHRASE_QUERY_SLOP, Integer.class);
    verify(jsonHelper, times(5)).unmarshallJsonToObject(Map.class, "{\"displayName\":\"1.0\"}");
    if (CollectionUtils.isNotEmpty(indexSearchRequest.getIndexSearchFilters())) {
        verify(elasticsearchHelper).addIndexSearchFilterBooleanClause(indexSearchRequest.getIndexSearchFilters(), BUSINESS_OBJECT_DEFINITION_SEARCH_INDEX_NAME, TAG_SEARCH_INDEX_NAME);
    }
    if (indexSearchRequest.isEnableHitHighlighting() != null) {
        verifyHitHighlightingInteractions(searchRequestBuilder, indexSearchRequest.isEnableHitHighlighting(), match);
    }
    if (CollectionUtils.isNotEmpty(indexSearchRequest.getFacetFields())) {
        verify(elasticsearchHelper).addFacetFieldAggregations(any(), any(SearchRequestBuilder.class));
        if (indexSearchRequest.getFacetFields().contains(ElasticsearchHelper.TAG_FACET)) {
            verify(elasticsearchHelper).getNestedTagTagIndexSearchResponseDto(searchResult);
            verify(elasticsearchHelper).getTagTagIndexSearchResponseDto(searchResult);
        }
        if (indexSearchRequest.getFacetFields().contains(ElasticsearchHelper.RESULT_TYPE_FACET)) {
            verify(elasticsearchHelper).getResultTypeIndexSearchResponseDto(searchResult);
        }
        verify(elasticsearchHelper).getFacetsResponse(any(ElasticsearchResponseDto.class), eq(BUSINESS_OBJECT_DEFINITION_SEARCH_INDEX_NAME), eq(TAG_SEARCH_INDEX_NAME));
    }
    verify(jestClientHelper).searchExecute(any());
    verify(searchResult).getTotal();
    verify(searchResult).getHits(Map.class);
    verifyNoMoreInteractions(searchRequestBuilder, searchRequestBuilderWithSource, searchRequestBuilderWithSize, searchRequestBuilderWithSorting, searchRequestBuilderWithHighlighting, searchResponse, searchHits, searchHit1, searchHit2, searchShardTarget1, searchShardTarget2, highlightField, listenableActionFuture, searchResult, metricAggregation, termsAggregation, entry1, entry2);
    verifyNoMoreInteractionsHelper();
}
Also used : SortBuilder(org.elasticsearch.search.sort.SortBuilder) HashMap(java.util.HashMap) TagIndexSearchResponseDto(org.finra.herd.model.dto.TagIndexSearchResponseDto) ArrayList(java.util.ArrayList) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) ResultTypeIndexSearchResponseDto(org.finra.herd.model.dto.ResultTypeIndexSearchResponseDto) IndexSearchResult(org.finra.herd.model.api.xml.IndexSearchResult) List(java.util.List) ArrayList(java.util.ArrayList) TermsAggregation(io.searchbox.core.search.aggregation.TermsAggregation) MetricAggregation(io.searchbox.core.search.aggregation.MetricAggregation) SearchResponse(org.elasticsearch.action.search.SearchResponse) IndexSearchResponse(org.finra.herd.model.api.xml.IndexSearchResponse) Map(java.util.Map) HashMap(java.util.HashMap) SearchHit(org.elasticsearch.search.SearchHit) Gson(com.google.gson.Gson) IndexSearchRequest(org.finra.herd.model.api.xml.IndexSearchRequest) IndexSearchResponse(org.finra.herd.model.api.xml.IndexSearchResponse) IndexSearchHighlightFields(org.finra.herd.model.dto.IndexSearchHighlightFields) TagTypeIndexSearchResponseDto(org.finra.herd.model.dto.TagTypeIndexSearchResponseDto) SearchHits(org.elasticsearch.search.SearchHits) IndexSearchHighlightField(org.finra.herd.model.dto.IndexSearchHighlightField) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) HighlightField(org.elasticsearch.search.fetch.subphase.highlight.HighlightField) IndexSearchHighlightField(org.finra.herd.model.dto.IndexSearchHighlightField) Text(org.elasticsearch.common.text.Text) IndexSearchResult(org.finra.herd.model.api.xml.IndexSearchResult) SearchResult(io.searchbox.core.SearchResult) IOException(java.io.IOException) SearchHit(org.elasticsearch.search.SearchHit) JsonElement(com.google.gson.JsonElement) SearchShardTarget(org.elasticsearch.search.SearchShardTarget) ElasticsearchResponseDto(org.finra.herd.model.dto.ElasticsearchResponseDto) HighlightBuilder(org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder)

Example 5 with TagIndexSearchResponseDto

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

the class ElasticsearchHelper method getTagTypeIndexSearchResponseDtosFromTermsAggregation.

/**
 * get Tag Type index response
 *
 * @param termsAggregation termsAggregation
 *
 * @return list of tag type index search dto
 */
private List<TagTypeIndexSearchResponseDto> getTagTypeIndexSearchResponseDtosFromTermsAggregation(TermsAggregation termsAggregation) {
    List<TermsAggregation.Entry> bucketsL0 = termsAggregation.getBuckets();
    List<TagTypeIndexSearchResponseDto> tagTypeIndexSearchResponseDtos = new ArrayList<>();
    for (TermsAggregation.Entry entryL1 : bucketsL0) {
        List<TagIndexSearchResponseDto> tagIndexSearchResponseDtos = new ArrayList<>();
        TermsAggregation termsAggregationL1 = entryL1.getTermsAggregation(TAGTYPE_NAME_AGGREGATION);
        List<TermsAggregation.Entry> bucketsL1 = termsAggregationL1.getBuckets();
        TagTypeIndexSearchResponseDto tagTypeIndexSearchResponseDto = new TagTypeIndexSearchResponseDto(entryL1.getKeyAsString(), tagIndexSearchResponseDtos, null);
        tagTypeIndexSearchResponseDtos.add(tagTypeIndexSearchResponseDto);
        for (TermsAggregation.Entry entryL2 : bucketsL1) {
            tagTypeIndexSearchResponseDto.setDisplayName(entryL2.getKeyAsString());
            TermsAggregation entryTermsAggregation = entryL2.getTermsAggregation(TAG_CODE_AGGREGATION);
            List<TermsAggregation.Entry> bucketsL2 = entryTermsAggregation.getBuckets();
            for (TermsAggregation.Entry entryL3 : bucketsL2) {
                TagIndexSearchResponseDto tagIndexSearchResponseDto = new TagIndexSearchResponseDto(entryL3.getKeyAsString(), entryL3.getCount(), null);
                tagIndexSearchResponseDtos.add(tagIndexSearchResponseDto);
                TermsAggregation entryEntryTermsAggregation = entryL3.getTermsAggregation(TAG_NAME_AGGREGATION);
                List<TermsAggregation.Entry> bucketsL3 = entryEntryTermsAggregation.getBuckets();
                for (TermsAggregation.Entry entryL4 : bucketsL3) {
                    tagIndexSearchResponseDto.setTagDisplayName(entryL4.getKeyAsString());
                }
            }
        }
    }
    return tagTypeIndexSearchResponseDtos;
}
Also used : TermsAggregation(io.searchbox.core.search.aggregation.TermsAggregation) TagIndexSearchResponseDto(org.finra.herd.model.dto.TagIndexSearchResponseDto) TagTypeIndexSearchResponseDto(org.finra.herd.model.dto.TagTypeIndexSearchResponseDto) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)13 TagIndexSearchResponseDto (org.finra.herd.model.dto.TagIndexSearchResponseDto)13 TagTypeIndexSearchResponseDto (org.finra.herd.model.dto.TagTypeIndexSearchResponseDto)12 Facet (org.finra.herd.model.api.xml.Facet)8 ElasticsearchResponseDto (org.finra.herd.model.dto.ElasticsearchResponseDto)7 Test (org.junit.Test)6 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)5 BusinessObjectDefinitionIndexSearchResponse (org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchResponse)3 BusinessObjectDefinitionSearchFilter (org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchFilter)3 ResultTypeIndexSearchResponseDto (org.finra.herd.model.dto.ResultTypeIndexSearchResponseDto)3 TermsAggregation (io.searchbox.core.search.aggregation.TermsAggregation)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)2 BusinessObjectDefinition (org.finra.herd.model.api.xml.BusinessObjectDefinition)2 BusinessObjectDefinitionIndexSearchRequest (org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchRequest)2 BusinessObjectDefinitionSearchKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchKey)2 BusinessObjectDefinitionIndexSearchResponseDto (org.finra.herd.model.dto.BusinessObjectDefinitionIndexSearchResponseDto)2