ElasticsearchHelper { public BoolQueryBuilder addIndexSearchFilterBooleanClause(List<IndexSearchFilter> indexSearchFilters, String bdefActiveIndex, String tagActiveIndex) { BoolQueryBuilder compoundBoolQueryBuilder = new BoolQueryBuilder(); for (IndexSearchFilter indexSearchFilter : indexSearchFilters) { BoolQueryBuilder indexSearchFilterClauseBuilder = applySearchFilterClause(indexSearchFilter, bdefActiveIndex, tagActiveIndex); if (BooleanUtils.isTrue(indexSearchFilter.isIsExclusionSearchFilter())) { compoundBoolQueryBuilder.mustNot(indexSearchFilterClauseBuilder); } else { compoundBoolQueryBuilder.must(indexSearchFilterClauseBuilder); } } return compoundBoolQueryBuilder; }  SearchRequestBuilder addFacetFieldAggregations(Set<String> facetFieldsList, SearchRequestBuilder searchRequestBuilder); BoolQueryBuilder addIndexSearchFilterBooleanClause(List<IndexSearchFilter> indexSearchFilters, String bdefActiveIndex, String tagActiveIndex); List<ResultTypeIndexSearchResponseDto> getResultTypeIndexSearchResponseDto(SearchResponse searchResponse); List<TagTypeIndexSearchResponseDto> getTagTagIndexSearchResponseDto(SearchResponse searchResponse); List<TagTypeIndexSearchResponseDto> getNestedTagTagIndexSearchResponseDto(SearchResponse searchResponse); List<Facet> getFacetsResponse(ElasticsearchResponseDto elasticsearchResponseDto, final String bdefActiveIndex, final String tagActiveIndex); Terms getAggregation(SearchResponse searchResponse, String aggregationName); Terms getNestedAggregation(SearchResponse searchResponse, String nestedAggregationName, String subAggregationName); String getSearchIndexType(final String indexName, final String bdefActiveIndex, final String tagActiveIndex); static final String DISPLAY_NAME_SOURCE; static final String NESTED_BDEFTAGS_PATH; static final String TAGTYPE_CODE_FIELD_TAG_INDEX; static final String TAGTYPE_NAME_FIELD_TAG_INDEX; static final String TAG_CODE_FIELD_TAG_INDEX; static final String TAG_NAME_FIELD_TAG_INDEX; static final String BDEF_TAGTYPE_CODE_FIELD; static final String BDEF_TAGTYPE_NAME_FIELD; static final String BDEF_TAG_CODE_FIELD; static final String BDEF_TAG_NAME_FIELD; static final String TAG_TAG_CODE_FIELD; static final String TAG_TAGTYPE_CODE_FIELD; static final String TAG_FACET_AGGS; static final String TAGTYPE_CODE_AGGREGATION; static final String TAGTYPE_NAME_AGGREGATION; static final String TAG_CODE_AGGREGATION; static final String TAG_NAME_AGGREGATION; static final String TAG_FACET; static final String RESULT_TYPE_FACET; static final String TAG_TYPE_FACET_AGGS; static final String RESULT_TYPE_AGGS; static final String RESULT_TYPE_FIELD; }
@Test public void testAddIndexSearchFilterBooleanClause() { TagKey tagKey = new TagKey(); tagKey.setTagCode(TAG_CODE); tagKey.setTagTypeCode(TAG_TYPE_CODE); IndexSearchResultTypeKey indexSearchResultTypeKey = new IndexSearchResultTypeKey(); indexSearchResultTypeKey.setIndexSearchResultType(INDEX_SEARCH_RESULT_TYPE); List<IndexSearchKey> indexSearchKeys = new ArrayList<>(); IndexSearchKey indexSearchKey = new IndexSearchKey(); indexSearchKey.setTagKey(tagKey); indexSearchKey.setIndexSearchResultTypeKey(indexSearchResultTypeKey); indexSearchKeys.add(indexSearchKey); List<IndexSearchFilter> indexSearchFilters = new ArrayList<>(); IndexSearchFilter indexSearchFilter1 = new IndexSearchFilter(); indexSearchFilter1.setIsExclusionSearchFilter(true); indexSearchFilter1.setIndexSearchKeys(indexSearchKeys); IndexSearchFilter indexSearchFilter2 = new IndexSearchFilter(); indexSearchFilter2.setIsExclusionSearchFilter(false); indexSearchFilter2.setIndexSearchKeys(indexSearchKeys); indexSearchFilters.add(indexSearchFilter1); indexSearchFilters.add(indexSearchFilter2); TagTypeEntity tagTypeEntity = new TagTypeEntity(); tagTypeEntity.setCode(tagKey.getTagCode()); TagEntity tagEntity = new TagEntity(); tagEntity.setTagCode(tagKey.getTagCode()); tagEntity.setTagType(tagTypeEntity); when(tagDaoHelper.getTagEntity(tagKey)).thenReturn(tagEntity); BoolQueryBuilder result = elasticsearchHelper.addIndexSearchFilterBooleanClause(indexSearchFilters, "bdefIndex", "tagIndex"); assertThat("Result is null.", result, is(notNullValue())); verify(tagDaoHelper, times(2)).getTagEntity(tagKey); verifyNoMoreInteractionsHelper(); }
@Test public void testAddIndexSearchFilterBooleanClauseWithTagHierarchy() { TagKey tagKey = new TagKey(); tagKey.setTagCode(TAG_CODE); tagKey.setTagTypeCode(TAG_TYPE_CODE); TagKey childTagKey = new TagKey(); childTagKey.setTagCode(TAG_CODE_2); childTagKey.setTagTypeCode(TAG_TYPE_CODE); IndexSearchResultTypeKey indexSearchResultTypeKey = new IndexSearchResultTypeKey(); indexSearchResultTypeKey.setIndexSearchResultType(INDEX_SEARCH_RESULT_TYPE); List<IndexSearchKey> indexSearchKeys = new ArrayList<>(); IndexSearchKey indexSearchKey = new IndexSearchKey(); indexSearchKey.setIncludeTagHierarchy(true); indexSearchKey.setTagKey(tagKey); indexSearchKey.setIndexSearchResultTypeKey(indexSearchResultTypeKey); indexSearchKeys.add(indexSearchKey); List<IndexSearchFilter> indexSearchFilters = new ArrayList<>(); IndexSearchFilter indexSearchFilter1 = new IndexSearchFilter(); indexSearchFilter1.setIsExclusionSearchFilter(true); indexSearchFilter1.setIndexSearchKeys(indexSearchKeys); IndexSearchFilter indexSearchFilter2 = new IndexSearchFilter(); indexSearchFilter2.setIsExclusionSearchFilter(false); indexSearchFilter2.setIndexSearchKeys(indexSearchKeys); indexSearchFilters.add(indexSearchFilter1); indexSearchFilters.add(indexSearchFilter2); TagTypeEntity tagTypeEntity = new TagTypeEntity(); tagTypeEntity.setCode(tagKey.getTagCode()); TagEntity tagEntity = new TagEntity(); tagEntity.setTagCode(tagKey.getTagCode()); tagEntity.setTagType(tagTypeEntity); TagEntity childTagEntity = new TagEntity(); childTagEntity.setTagCode(childTagKey.getTagCode()); childTagEntity.setTagType(tagTypeEntity); childTagEntity.setParentTagEntity(tagEntity); tagEntity.setChildrenTagEntities(Lists.newArrayList(childTagEntity)); when(tagDaoHelper.getTagEntity(tagKey)).thenReturn(tagEntity); when(tagDaoHelper.getTagChildrenEntities(tagEntity)).thenReturn(Lists.newArrayList(childTagEntity)); BoolQueryBuilder result = elasticsearchHelper.addIndexSearchFilterBooleanClause(indexSearchFilters, "bdefIndex", "tagIndex"); assertThat("Result is null.", result, is(notNullValue())); verify(tagDaoHelper, times(2)).getTagEntity(tagKey); verify(tagDaoHelper, times(2)).getTagChildrenEntities(tagEntity); verifyNoMoreInteractionsHelper(); }