Search in sources :

Example 1 with IndexSearchResultTypeKey

use of org.finra.herd.model.api.xml.IndexSearchResultTypeKey in project herd by FINRAOS.

the class ElasticSearchHelperTest method testAddIndexSearchFilterBooleanClause.

@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);
    BoolQueryBuilder result = elasticsearchHelper.addIndexSearchFilterBooleanClause(indexSearchFilters, "bdefIndex", "tagIndex");
    assertThat("Result is null.", result, is(notNullValue()));
}
Also used : IndexSearchKey(org.finra.herd.model.api.xml.IndexSearchKey) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) TagKey(org.finra.herd.model.api.xml.TagKey) ArrayList(java.util.ArrayList) IndexSearchResultTypeKey(org.finra.herd.model.api.xml.IndexSearchResultTypeKey) IndexSearchFilter(org.finra.herd.model.api.xml.IndexSearchFilter) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 2 with IndexSearchResultTypeKey

use of org.finra.herd.model.api.xml.IndexSearchResultTypeKey in project herd by FINRAOS.

the class IndexSearchDaoTest method indexSearchWithResultTypeExcludeFilterAndHitHighlighting.

@Test
public void indexSearchWithResultTypeExcludeFilterAndHitHighlighting() throws IOException {
    // Create a new fields set that will be used when testing the index search method
    final Set<String> fields = new HashSet<>();
    // Create an index search key
    final IndexSearchKey indexSearchKey = new IndexSearchKey();
    // Create a result type key
    final IndexSearchResultTypeKey resultTypeKey = new IndexSearchResultTypeKey(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
    indexSearchKey.setIndexSearchResultTypeKey(resultTypeKey);
    // Create an index search keys list and add the previously defined key to it
    final List<IndexSearchKey> indexSearchKeys = Collections.singletonList(indexSearchKey);
    // Create an index search filter with the keys previously defined
    final IndexSearchFilter indexSearchFilter = new IndexSearchFilter(NO_EXCLUSION_SEARCH_FILTER, indexSearchKeys);
    // Set exclude flag to true
    indexSearchFilter.setIsExclusionSearchFilter(true);
    List<IndexSearchFilter> indexSearchFilters = Collections.singletonList(indexSearchFilter);
    // result type facet only
    testIndexSearch(fields, indexSearchFilters, null, ENABLE_HIT_HIGHLIGHTING);
}
Also used : IndexSearchKey(org.finra.herd.model.api.xml.IndexSearchKey) IndexSearchResultTypeKey(org.finra.herd.model.api.xml.IndexSearchResultTypeKey) IndexSearchFilter(org.finra.herd.model.api.xml.IndexSearchFilter) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with IndexSearchResultTypeKey

use of org.finra.herd.model.api.xml.IndexSearchResultTypeKey in project herd by FINRAOS.

the class IndexSearchDaoTest method indexSearchTestWithResultTypeFilterAndExcludeFlagSet.

@Test
public void indexSearchTestWithResultTypeFilterAndExcludeFlagSet() throws IOException {
    // Create a new fields set that will be used when testing the index search method
    final Set<String> fields = new HashSet<>();
    // Create an index search key
    final IndexSearchKey indexSearchKey = new IndexSearchKey();
    // Create a result type key
    final IndexSearchResultTypeKey resultTypeKey = new IndexSearchResultTypeKey(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
    indexSearchKey.setIndexSearchResultTypeKey(resultTypeKey);
    // Create an index search keys list and add the previously defined key to it
    final List<IndexSearchKey> indexSearchKeys = Collections.singletonList(indexSearchKey);
    // Create an index search filter with the keys previously defined
    final IndexSearchFilter indexSearchFilter = new IndexSearchFilter(NO_EXCLUSION_SEARCH_FILTER, indexSearchKeys);
    // Set exclude flag to true
    indexSearchFilter.setIsExclusionSearchFilter(true);
    List<IndexSearchFilter> indexSearchFilters = Collections.singletonList(indexSearchFilter);
    // result type facet only
    testIndexSearch(fields, indexSearchFilters, null, NO_ENABLE_HIT_HIGHLIGHTING);
}
Also used : IndexSearchKey(org.finra.herd.model.api.xml.IndexSearchKey) IndexSearchResultTypeKey(org.finra.herd.model.api.xml.IndexSearchResultTypeKey) IndexSearchFilter(org.finra.herd.model.api.xml.IndexSearchFilter) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with IndexSearchResultTypeKey

use of org.finra.herd.model.api.xml.IndexSearchResultTypeKey in project herd by FINRAOS.

the class IndexSearchServiceTest method testIndexSearchInvalidIndexSearchKey.

@Test
public void testIndexSearchInvalidIndexSearchKey() {
    // Create an index search key that contains both tag and result type keys.
    final IndexSearchKey indexSearchKey = new IndexSearchKey(new TagKey(TAG_TYPE_CODE, TAG_CODE), new IndexSearchResultTypeKey(INDEX_SEARCH_RESULT_TYPE));
    // Create an index search filter.
    final IndexSearchFilter indexSearchFilter = new IndexSearchFilter(NO_EXCLUSION_SEARCH_FILTER, Collections.singletonList(indexSearchKey));
    // Create an index search request.
    final IndexSearchRequest indexSearchRequest = new IndexSearchRequest(SEARCH_TERM, Collections.singletonList(indexSearchFilter), NO_INDEX_SEARCH_FACET_FIELDS, NO_ENABLE_HIT_HIGHLIGHTING);
    // Create a set of fields.
    final Set<String> fields = Sets.newHashSet(FIELD_DISPLAY_NAME, FIELD_SHORT_DESCRIPTION);
    // Try to call the method under test.
    try {
        indexSearchService.indexSearch(indexSearchRequest, fields, NO_MATCH);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("Exactly one instance of index search result type key or tag key must be specified.", e.getMessage());
    }
}
Also used : IndexSearchKey(org.finra.herd.model.api.xml.IndexSearchKey) TagKey(org.finra.herd.model.api.xml.TagKey) IndexSearchResultTypeKey(org.finra.herd.model.api.xml.IndexSearchResultTypeKey) IndexSearchRequest(org.finra.herd.model.api.xml.IndexSearchRequest) IndexSearchFilter(org.finra.herd.model.api.xml.IndexSearchFilter) Test(org.junit.Test)

Example 5 with IndexSearchResultTypeKey

use of org.finra.herd.model.api.xml.IndexSearchResultTypeKey in project herd by FINRAOS.

the class IndexSearchServiceTest method testIndexSearchWithResultTypeFilter.

@Test
public void testIndexSearchWithResultTypeFilter() {
    // Create an index search key
    final IndexSearchKey indexSearchKey = new IndexSearchKey();
    // Create a tag key
    final IndexSearchResultTypeKey resultTypeKey = new IndexSearchResultTypeKey(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
    indexSearchKey.setIndexSearchResultTypeKey(resultTypeKey);
    // Create an index search keys list and add the previously defined key to it
    final List<IndexSearchKey> indexSearchKeys = Collections.singletonList(indexSearchKey);
    // Create an index search filter with the keys previously defined
    final IndexSearchFilter indexSearchFilter = new IndexSearchFilter(EXCLUSION_SEARCH_FILTER, indexSearchKeys);
    List<IndexSearchFilter> indexSearchFilters = Collections.singletonList(indexSearchFilter);
    // Create index search request
    final IndexSearchRequest indexSearchRequest = new IndexSearchRequest(SEARCH_TERM, indexSearchFilters, null, false);
    // Create a set of fields.
    final Set<String> fields = Sets.newHashSet(FIELD_DISPLAY_NAME, FIELD_SHORT_DESCRIPTION);
    // Create a new index search result key and populate it with a tag key
    final IndexSearchResultKey indexSearchResultKeyBusinessObjectDefinition = new IndexSearchResultKey(null, new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME));
    // Create a new index search result key and populate it with a tag key
    final IndexSearchResultKey indexSearchResultKeyTag = new IndexSearchResultKey(new TagKey(TAG_TYPE, TAG_CODE), null);
    // Create a new index search results
    final IndexSearchResult indexSearchResultBusinessObjectDefinition = new IndexSearchResult(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name(), new SearchIndexKey(BUSINESS_OBJECT_DEFINITION_SEARCH_INDEX_NAME), indexSearchResultKeyBusinessObjectDefinition, BDEF_DISPLAY_NAME, BDEF_SHORT_DESCRIPTION, null);
    final IndexSearchResult indexSearchResultTag = new IndexSearchResult(SearchIndexTypeEntity.SearchIndexTypes.TAG.name(), new SearchIndexKey(TAG_SEARCH_INDEX_NAME), indexSearchResultKeyTag, TAG_DISPLAY_NAME, TAG_DESCRIPTION, null);
    // Create a list to contain the index search results
    final List<IndexSearchResult> indexSearchResults = new ArrayList<>();
    indexSearchResults.add(indexSearchResultBusinessObjectDefinition);
    indexSearchResults.add(indexSearchResultTag);
    // Construct an index search response
    final IndexSearchResponse indexSearchResponse = new IndexSearchResponse(TOTAL_INDEX_SEARCH_RESULTS, indexSearchResults, null);
    // Mock the call to the index search service
    when(alternateKeyHelper.validateStringParameter("An", "index search result type", SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name())).thenReturn(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
    when(searchIndexDaoHelper.getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name())).thenReturn(SEARCH_INDEX_NAME);
    when(searchIndexDaoHelper.getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.TAG.name())).thenReturn(SEARCH_INDEX_NAME_2);
    when(indexSearchDao.indexSearch(indexSearchRequest, fields, NO_MATCH, SEARCH_INDEX_NAME, SEARCH_INDEX_NAME_2)).thenReturn(indexSearchResponse);
    // Call the method under test.
    IndexSearchResponse result = indexSearchService.indexSearch(indexSearchRequest, fields, NO_MATCH);
    // Verify the external calls.
    verify(alternateKeyHelper).validateStringParameter("An", "index search result type", SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
    verify(searchIndexTypeDaoHelper).getSearchIndexTypeEntity(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
    verify(searchIndexDaoHelper).getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
    verify(searchIndexDaoHelper).getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.TAG.name());
    verify(indexSearchDao).indexSearch(indexSearchRequest, fields, NO_MATCH, SEARCH_INDEX_NAME, SEARCH_INDEX_NAME_2);
    verifyNoMoreInteractionsHelper();
    // Validate the result.
    assertEquals(indexSearchResponse, result);
}
Also used : IndexSearchKey(org.finra.herd.model.api.xml.IndexSearchKey) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) ArrayList(java.util.ArrayList) IndexSearchResultTypeKey(org.finra.herd.model.api.xml.IndexSearchResultTypeKey) IndexSearchRequest(org.finra.herd.model.api.xml.IndexSearchRequest) IndexSearchResultKey(org.finra.herd.model.api.xml.IndexSearchResultKey) SearchIndexKey(org.finra.herd.model.api.xml.SearchIndexKey) IndexSearchResponse(org.finra.herd.model.api.xml.IndexSearchResponse) TagKey(org.finra.herd.model.api.xml.TagKey) IndexSearchResult(org.finra.herd.model.api.xml.IndexSearchResult) IndexSearchFilter(org.finra.herd.model.api.xml.IndexSearchFilter) Test(org.junit.Test)

Aggregations

IndexSearchFilter (org.finra.herd.model.api.xml.IndexSearchFilter)9 IndexSearchKey (org.finra.herd.model.api.xml.IndexSearchKey)9 IndexSearchResultTypeKey (org.finra.herd.model.api.xml.IndexSearchResultTypeKey)9 Test (org.junit.Test)9 TagKey (org.finra.herd.model.api.xml.TagKey)6 IndexSearchRequest (org.finra.herd.model.api.xml.IndexSearchRequest)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)3 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)3 IndexSearchResponse (org.finra.herd.model.api.xml.IndexSearchResponse)3 IndexSearchResult (org.finra.herd.model.api.xml.IndexSearchResult)3 IndexSearchResultKey (org.finra.herd.model.api.xml.IndexSearchResultKey)3 SearchIndexKey (org.finra.herd.model.api.xml.SearchIndexKey)3 TagEntity (org.finra.herd.model.jpa.TagEntity)3 TagTypeEntity (org.finra.herd.model.jpa.TagTypeEntity)3 SearchIndexTypeEntity (org.finra.herd.model.jpa.SearchIndexTypeEntity)2 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)1 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)1