Search in sources :

Example 1 with IndexSearchFilter

use of org.finra.herd.model.api.xml.IndexSearchFilter 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 IndexSearchFilter

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

the class IndexSearchServiceImpl method validateIndexSearchFilters.

/**
 * Validates the specified index search filters.
 *
 * @param indexSearchFilters the index search filters
 */
private void validateIndexSearchFilters(List<IndexSearchFilter> indexSearchFilters) {
    // Validate that the search filters list is not empty
    Assert.notEmpty(indexSearchFilters, "At least one index search filter must be specified.");
    for (IndexSearchFilter searchFilter : indexSearchFilters) {
        // Silently skip a search filter which is null
        if (searchFilter != null) {
            // Validate that each search filter has at least one index search key
            Assert.notEmpty(searchFilter.getIndexSearchKeys(), "At least one index search key must be specified.");
            // Guard against a single null element in the index search keys list
            if (searchFilter.getIndexSearchKeys().get(0) != null) {
                // Get the instance type of the key in the search filter, match all other keys with this
                Class<?> expectedInstanceType = searchFilter.getIndexSearchKeys().get(0).getIndexSearchResultTypeKey() != null ? IndexSearchResultTypeKey.class : TagKey.class;
                searchFilter.getIndexSearchKeys().forEach(indexSearchKey -> {
                    // Validate that each search key has either an index search result type key or a tag key
                    Assert.isTrue((indexSearchKey.getIndexSearchResultTypeKey() != null) ^ (indexSearchKey.getTagKey() != null), "Exactly one instance of index search result type key or tag key must be specified.");
                    Class<?> actualInstanceType = indexSearchKey.getIndexSearchResultTypeKey() != null ? IndexSearchResultTypeKey.class : TagKey.class;
                    // Validate that search keys within the same filter have either index search result type keys or tag keys
                    Assert.isTrue(expectedInstanceType.equals(actualInstanceType), "Index search keys should be a homogeneous list of either index search result type keys or tag keys.");
                    // Validate tag key if present
                    if (indexSearchKey.getTagKey() != null) {
                        tagHelper.validateTagKey(indexSearchKey.getTagKey());
                        // Validates that a tag entity exists for the specified tag key and gets the actual key from the database
                        // We then modify the index search filter key to use the actual values because it eventually becomes a filter query and it will not
                        // automatically be case-sensitivity and whitespace resilient.
                        TagEntity actualTagEntity = tagDaoHelper.getTagEntity(indexSearchKey.getTagKey());
                        TagKey tagKey = new TagKey(actualTagEntity.getTagType().getCode(), actualTagEntity.getTagCode());
                        indexSearchKey.setTagKey(tagKey);
                    }
                    // Validate search result type key if present
                    if (indexSearchKey.getIndexSearchResultTypeKey() != null) {
                        validateIndexSearchResultTypeKey(indexSearchKey.getIndexSearchResultTypeKey());
                        // Ensure that specified search index type exists.
                        searchIndexTypeDaoHelper.getSearchIndexTypeEntity(indexSearchKey.getIndexSearchResultTypeKey().getIndexSearchResultType());
                    }
                });
            }
        }
    }
}
Also used : TagEntity(org.finra.herd.model.jpa.TagEntity) TagKey(org.finra.herd.model.api.xml.TagKey) IndexSearchFilter(org.finra.herd.model.api.xml.IndexSearchFilter)

Example 3 with IndexSearchFilter

use of org.finra.herd.model.api.xml.IndexSearchFilter 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 4 with IndexSearchFilter

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

the class IndexSearchDaoTest method indexSearchTestWithTagKeyFilter.

@Test
public void indexSearchTestWithTagKeyFilter() 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 tag key
    final TagKey tagKey = new TagKey(TAG_TYPE_CODE, TAG_CODE);
    indexSearchKey.setTagKey(tagKey);
    // 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);
    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) TagKey(org.finra.herd.model.api.xml.TagKey) IndexSearchFilter(org.finra.herd.model.api.xml.IndexSearchFilter) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with IndexSearchFilter

use of org.finra.herd.model.api.xml.IndexSearchFilter 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)

Aggregations

IndexSearchFilter (org.finra.herd.model.api.xml.IndexSearchFilter)12 IndexSearchKey (org.finra.herd.model.api.xml.IndexSearchKey)11 Test (org.junit.Test)11 IndexSearchResultTypeKey (org.finra.herd.model.api.xml.IndexSearchResultTypeKey)9 TagKey (org.finra.herd.model.api.xml.TagKey)9 HashSet (java.util.HashSet)5 IndexSearchRequest (org.finra.herd.model.api.xml.IndexSearchRequest)5 ArrayList (java.util.ArrayList)4 TagEntity (org.finra.herd.model.jpa.TagEntity)4 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 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