Search in sources :

Example 1 with IndexSearchKey

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

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

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

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

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

the class ElasticsearchHelper method applySearchFilterClause.

/**
 * Resolves the search filters into an Elasticsearch {@link BoolQueryBuilder}
 *
 * @param indexSearchFilter the specified search filter
 * @param bdefActiveIndex the name of the bdef active index
 * @param tagActiveIndex the name of the tag active index
 *
 * @return {@link BoolQueryBuilder} the resolved filter query
 */
private BoolQueryBuilder applySearchFilterClause(IndexSearchFilter indexSearchFilter, String bdefActiveIndex, String tagActiveIndex) {
    BoolQueryBuilder indexSearchFilterClauseBuilder = new BoolQueryBuilder();
    for (IndexSearchKey indexSearchKey : indexSearchFilter.getIndexSearchKeys()) {
        if (indexSearchKey.getTagKey() != null) {
            // Add constant-score term queries for tagType-code and tag-code from the tag-key.
            ConstantScoreQueryBuilder searchKeyQueryBuilder = QueryBuilders.constantScoreQuery(QueryBuilders.boolQuery().should(QueryBuilders.boolQuery().must(QueryBuilders.termQuery(BDEF_TAGTYPE_CODE_FIELD, indexSearchKey.getTagKey().getTagTypeCode())).must(QueryBuilders.termQuery(BDEF_TAG_CODE_FIELD, indexSearchKey.getTagKey().getTagCode()))).should(QueryBuilders.boolQuery().must(QueryBuilders.termQuery(TAG_TAGTYPE_CODE_FIELD, indexSearchKey.getTagKey().getTagTypeCode())).must(QueryBuilders.termQuery(TAG_TAG_CODE_FIELD, indexSearchKey.getTagKey().getTagCode()))));
            // Individual index search keys are OR-ed
            indexSearchFilterClauseBuilder.should(searchKeyQueryBuilder);
        }
        if (indexSearchKey.getIndexSearchResultTypeKey() != null) {
            String indexSearchResultType = indexSearchKey.getIndexSearchResultTypeKey().getIndexSearchResultType();
            String indexName = indexSearchResultType.equalsIgnoreCase(SearchIndexTypeEntity.SearchIndexTypes.TAG.name()) ? tagActiveIndex : bdefActiveIndex;
            // Add constant-score term queries for tagType-code and tag-code from the tag-key.
            ConstantScoreQueryBuilder searchKeyQueryBuilder = QueryBuilders.constantScoreQuery(QueryBuilders.boolQuery().must(QueryBuilders.termQuery(RESULT_TYPE_FIELD, indexName)));
            // Individual index search keys are OR-ed
            indexSearchFilterClauseBuilder.should(searchKeyQueryBuilder);
        }
    }
    return indexSearchFilterClauseBuilder;
}
Also used : IndexSearchKey(org.finra.herd.model.api.xml.IndexSearchKey) ConstantScoreQueryBuilder(org.elasticsearch.index.query.ConstantScoreQueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder)

Aggregations

IndexSearchKey (org.finra.herd.model.api.xml.IndexSearchKey)12 IndexSearchFilter (org.finra.herd.model.api.xml.IndexSearchFilter)11 Test (org.junit.Test)11 IndexSearchResultTypeKey (org.finra.herd.model.api.xml.IndexSearchResultTypeKey)9 TagKey (org.finra.herd.model.api.xml.TagKey)8 HashSet (java.util.HashSet)5 IndexSearchRequest (org.finra.herd.model.api.xml.IndexSearchRequest)5 ArrayList (java.util.ArrayList)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 TagEntity (org.finra.herd.model.jpa.TagEntity)3 TagTypeEntity (org.finra.herd.model.jpa.TagTypeEntity)3 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)2 SearchIndexTypeEntity (org.finra.herd.model.jpa.SearchIndexTypeEntity)2 ConstantScoreQueryBuilder (org.elasticsearch.index.query.ConstantScoreQueryBuilder)1 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)1