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()));
}
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);
}
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);
}
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);
}
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;
}
Aggregations