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