use of org.sonar.server.es.searchrequest.RequestFiltersComputer.AllFilters in project sonarqube by SonarSource.
the class RequestFiltersComputerTest method getQueryFilters_contains_all_filters_when_no_declared_sticky_topAggregation.
@Test
public void getQueryFilters_contains_all_filters_when_no_declared_sticky_topAggregation() {
AllFilters allFilters = randomNonEmptyAllFilters();
Set<TopAggregationDefinition<?>> atLeastOneNonStickyTopAggs = randomNonEmptyTopAggregations(() -> false);
RequestFiltersComputer underTest = new RequestFiltersComputer(allFilters, atLeastOneNonStickyTopAggs);
assertThat(underTest.getQueryFilters()).contains(toBoolQuery(allFilters.stream()));
}
use of org.sonar.server.es.searchrequest.RequestFiltersComputer.AllFilters in project sonarqube by SonarSource.
the class RequestFiltersComputerTest method getPostFilters_returns_empty_when_no_declared_sticky_topAggregation.
@Test
public void getPostFilters_returns_empty_when_no_declared_sticky_topAggregation() {
AllFilters allFilters = randomNonEmptyAllFilters();
Set<TopAggregationDefinition<?>> atLeastOneNonStickyTopAggs = randomNonEmptyTopAggregations(() -> false);
RequestFiltersComputer underTest = new RequestFiltersComputer(allFilters, atLeastOneNonStickyTopAggs);
assertThat(underTest.getPostFilters()).isEmpty();
}
use of org.sonar.server.es.searchrequest.RequestFiltersComputer.AllFilters in project sonarqube by SonarSource.
the class RequestFiltersComputerTest method filters_on_nestedField_of_sticky_TopAggregation_go_to_PostFilters_and_TopAgg_Filters_on_other_fields.
@Test
public void filters_on_nestedField_of_sticky_TopAggregation_go_to_PostFilters_and_TopAgg_Filters_on_other_fields() {
String field1 = "field1";
String field2 = "field2";
String field3 = "field3";
String nestField = "nestedField";
String nestField_value1 = "nestedField_value1";
String nestField_value2 = "nestedField_value2";
AllFilters allFilters = newAllFilters();
// filter without top aggregation
QueryBuilder queryFilter = newQuery("query_filter");
allFilters.addFilter("query_filter", new SimpleFieldFilterScope("text"), queryFilter);
// nestedField of field1 with value1: has topAggs and two filters
NestedFieldFilterScope<String> filterScopeNestField1_value1 = new NestedFieldFilterScope<>(field1, nestField, nestField_value1);
NestedFieldTopAggregationDefinition<String> stickyTopAggNestedField1_value1 = newNestedFieldTopAggDef(field1, nestField, nestField_value1, STICKY);
NestedFieldTopAggregationDefinition<String> nonStickyTopAggNestedField1_value1 = newNestedFieldTopAggDef(field1, nestField, nestField_value1, NON_STICKY);
QueryBuilder filterNestedField1_value1_1 = newQuery("filterNestedField1_value1_1");
QueryBuilder filterNestedField1_value1_2 = newQuery("filterNestedField1_value1_2");
allFilters.addFilter("filter_nested_field1_value1_1", filterScopeNestField1_value1, filterNestedField1_value1_1);
allFilters.addFilter("filter_nested_field1_value1_2", filterScopeNestField1_value1, filterNestedField1_value1_2);
// nestedField of field1 with value2: has topAggs and two filters
NestedFieldFilterScope<String> filterScopeNestField1_value2 = new NestedFieldFilterScope<>(field1, nestField, nestField_value2);
NestedFieldTopAggregationDefinition<String> stickyTopAggNestedField1_value2 = newNestedFieldTopAggDef(field1, nestField, nestField_value2, STICKY);
NestedFieldTopAggregationDefinition<String> nonStickyTopAggNestedField1_value2 = newNestedFieldTopAggDef(field1, nestField, nestField_value2, NON_STICKY);
QueryBuilder filterNestedField1_value2_1 = newQuery("filterNestedField1_value2_1");
QueryBuilder filterNestedField1_value2_2 = newQuery("filterNestedField1_value2_2");
allFilters.addFilter("filter_nested_field1_value2_1", filterScopeNestField1_value2, filterNestedField1_value2_1);
allFilters.addFilter("filter_nested_field1_value2_2", filterScopeNestField1_value2, filterNestedField1_value2_2);
// [EDGE CASE] topAgg directly on field1: has topAggs and two filters
SimpleFieldFilterScope filterScopeField1 = new SimpleFieldFilterScope(field1);
SimpleFieldTopAggregationDefinition stickyTopAggField1 = new SimpleFieldTopAggregationDefinition(field1, STICKY);
SimpleFieldTopAggregationDefinition nonStickyTopAggField1 = new SimpleFieldTopAggregationDefinition(field1, NON_STICKY);
QueryBuilder filterField1_1 = newQuery("filterField1_1");
QueryBuilder filterField1_2 = newQuery("filterField1_2");
allFilters.addFilter("filter_field1_1", filterScopeField1, filterField1_1);
allFilters.addFilter("filter_field1_2", filterScopeField1, filterField1_2);
// other field: has topAggs and two filters too
SimpleFieldFilterScope filterScopeField2 = new SimpleFieldFilterScope(field2);
SimpleFieldTopAggregationDefinition stickyTopAggField2 = new SimpleFieldTopAggregationDefinition(field2, STICKY);
SimpleFieldTopAggregationDefinition nonStickyTopAggField2 = new SimpleFieldTopAggregationDefinition(field2, NON_STICKY);
QueryBuilder filterField2_1 = newQuery("filterField2_1");
QueryBuilder filterField2_2 = newQuery("filterField2_2");
allFilters.addFilter("filter_field2_1", filterScopeField2, filterField2_1);
allFilters.addFilter("filter_field2_2", filterScopeField2, filterField2_2);
// nestedField of another field (even though nestedField name and values are the same): has topAggs and two filters
NestedFieldFilterScope<String> filterScopeNestField3_value = new NestedFieldFilterScope<>(field3, nestField, nestField_value1);
NestedFieldTopAggregationDefinition<String> stickyTopAggNestedField3 = newNestedFieldTopAggDef(field3, nestField, nestField_value1, STICKY);
NestedFieldTopAggregationDefinition<String> nonStickyTopAggNestedField3 = newNestedFieldTopAggDef(field3, nestField, nestField_value1, NON_STICKY);
QueryBuilder filterNestedField3_1 = newQuery("filterNestedField3_1");
QueryBuilder filterNestedField3_2 = newQuery("filterNestedField3_2");
allFilters.addFilter("filter_nested_field3_1", filterScopeNestField3_value, filterNestedField3_1);
allFilters.addFilter("filter_nested_field3_2", filterScopeNestField3_value, filterNestedField3_2);
Set<TopAggregationDefinition<?>> declaredTopAggregations = ImmutableSet.of(stickyTopAggNestedField1_value1, nonStickyTopAggNestedField1_value1, stickyTopAggNestedField1_value2, nonStickyTopAggNestedField1_value2, stickyTopAggField1, nonStickyTopAggField1, stickyTopAggField2, nonStickyTopAggField2, stickyTopAggNestedField3, nonStickyTopAggNestedField3);
RequestFiltersComputer underTest = new RequestFiltersComputer(allFilters, declaredTopAggregations);
assertThat(underTest.getQueryFilters()).contains(toBoolQuery(queryFilter));
QueryBuilder[] postFilters = { filterNestedField1_value1_1, filterNestedField1_value1_2, filterNestedField1_value2_1, filterNestedField1_value2_2, filterField1_1, filterField1_2, filterField2_1, filterField2_2, filterNestedField3_1, filterNestedField3_2 };
assertThat(underTest.getPostFilters()).contains(toBoolQuery(postFilters));
assertTopAggregationFilter(underTest, stickyTopAggNestedField1_value1, filterNestedField1_value2_1, filterNestedField1_value2_2, filterField1_1, filterField1_2, filterField2_1, filterField2_2, filterNestedField3_1, filterNestedField3_2);
assertTopAggregationFilter(underTest, nonStickyTopAggNestedField1_value1, postFilters);
assertTopAggregationFilter(underTest, stickyTopAggNestedField1_value2, filterNestedField1_value1_1, filterNestedField1_value1_2, filterField1_1, filterField1_2, filterField2_1, filterField2_2, filterNestedField3_1, filterNestedField3_2);
assertTopAggregationFilter(underTest, nonStickyTopAggNestedField1_value2, postFilters);
assertTopAggregationFilter(underTest, stickyTopAggField1, filterField2_1, filterField2_2, filterNestedField3_1, filterNestedField3_2);
assertTopAggregationFilter(underTest, nonStickyTopAggField1, postFilters);
assertTopAggregationFilter(underTest, stickyTopAggField2, filterNestedField1_value1_1, filterNestedField1_value1_2, filterNestedField1_value2_1, filterNestedField1_value2_2, filterField1_1, filterField1_2, filterNestedField3_1, filterNestedField3_2);
assertTopAggregationFilter(underTest, nonStickyTopAggField2, postFilters);
assertTopAggregationFilter(underTest, stickyTopAggNestedField3, filterNestedField1_value1_1, filterNestedField1_value1_2, filterNestedField1_value2_1, filterNestedField1_value2_2, filterField1_1, filterField1_2, filterField2_1, filterField2_2);
assertTopAggregationFilter(underTest, nonStickyTopAggNestedField3, postFilters);
}
use of org.sonar.server.es.searchrequest.RequestFiltersComputer.AllFilters in project sonarqube by SonarSource.
the class RequestFiltersComputerTest method getPostFilters_returns_empty_when_no_declared_topAggregation.
@Test
public void getPostFilters_returns_empty_when_no_declared_topAggregation() {
AllFilters allFilters = randomNonEmptyAllFilters();
RequestFiltersComputer underTest = new RequestFiltersComputer(allFilters, Collections.emptySet());
assertThat(underTest.getPostFilters()).isEmpty();
}
use of org.sonar.server.es.searchrequest.RequestFiltersComputer.AllFilters in project sonarqube by SonarSource.
the class IssueIndex method createAllFilters.
private AllFilters createAllFilters(IssueQuery query) {
AllFilters filters = RequestFiltersComputer.newAllFilters();
filters.addFilter("__indexType", new SimpleFieldFilterScope(FIELD_INDEX_TYPE), termQuery(FIELD_INDEX_TYPE, TYPE_ISSUE.getName()));
filters.addFilter("__authorization", new SimpleFieldFilterScope("parent"), createAuthorizationFilter());
// Issue is assigned Filter
if (Boolean.TRUE.equals(query.assigned())) {
filters.addFilter(IS_ASSIGNED_FILTER, Facet.ASSIGNEES.getFilterScope(), existsQuery(FIELD_ISSUE_ASSIGNEE_UUID));
} else if (Boolean.FALSE.equals(query.assigned())) {
filters.addFilter(IS_ASSIGNED_FILTER, ASSIGNEES.getFilterScope(), boolQuery().mustNot(existsQuery(FIELD_ISSUE_ASSIGNEE_UUID)));
}
// Issue is Resolved Filter
if (Boolean.TRUE.equals(query.resolved())) {
filters.addFilter("__isResolved", Facet.RESOLUTIONS.getFilterScope(), existsQuery(FIELD_ISSUE_RESOLUTION));
} else if (Boolean.FALSE.equals(query.resolved())) {
filters.addFilter("__isResolved", Facet.RESOLUTIONS.getFilterScope(), boolQuery().mustNot(existsQuery(FIELD_ISSUE_RESOLUTION)));
}
// Field Filters
filters.addFilter(FIELD_ISSUE_KEY, new SimpleFieldFilterScope(FIELD_ISSUE_KEY), createTermsFilter(FIELD_ISSUE_KEY, query.issueKeys()));
filters.addFilter(FIELD_ISSUE_ASSIGNEE_UUID, ASSIGNEES.getFilterScope(), createTermsFilter(FIELD_ISSUE_ASSIGNEE_UUID, query.assignees()));
filters.addFilter(FIELD_ISSUE_SCOPE, SCOPES.getFilterScope(), createTermsFilter(FIELD_ISSUE_SCOPE, query.scopes()));
filters.addFilter(FIELD_ISSUE_LANGUAGE, LANGUAGES.getFilterScope(), createTermsFilter(FIELD_ISSUE_LANGUAGE, query.languages()));
filters.addFilter(FIELD_ISSUE_TAGS, TAGS.getFilterScope(), createTermsFilter(FIELD_ISSUE_TAGS, query.tags()));
filters.addFilter(FIELD_ISSUE_TYPE, TYPES.getFilterScope(), createTermsFilter(FIELD_ISSUE_TYPE, query.types()));
filters.addFilter(FIELD_ISSUE_RESOLUTION, RESOLUTIONS.getFilterScope(), createTermsFilter(FIELD_ISSUE_RESOLUTION, query.resolutions()));
filters.addFilter(FIELD_ISSUE_AUTHOR_LOGIN, AUTHOR.getFilterScope(), createTermsFilter(FIELD_ISSUE_AUTHOR_LOGIN, query.authors()));
filters.addFilter(FIELD_ISSUE_RULE_UUID, RULES.getFilterScope(), createTermsFilter(FIELD_ISSUE_RULE_UUID, query.ruleUuids()));
filters.addFilter(FIELD_ISSUE_STATUS, STATUSES.getFilterScope(), createTermsFilter(FIELD_ISSUE_STATUS, query.statuses()));
// security category
addSecurityCategoryFilter(FIELD_ISSUE_OWASP_TOP_10, OWASP_TOP_10, query.owaspTop10(), filters);
addSecurityCategoryFilter(FIELD_ISSUE_SANS_TOP_25, SANS_TOP_25, query.sansTop25(), filters);
addSecurityCategoryFilter(FIELD_ISSUE_CWE, CWE, query.cwe(), filters);
addSecurityCategoryFilter(FIELD_ISSUE_SQ_SECURITY_CATEGORY, SONARSOURCE_SECURITY, query.sonarsourceSecurity(), filters);
addSeverityFilter(query, filters);
addComponentRelatedFilters(query, filters);
addDatesFilter(filters, query);
addCreatedAfterByProjectsFilter(filters, query);
addNewCodeReferenceFilter(filters, query);
addNewCodeReferenceFilterByProjectsFilter(filters, query);
return filters;
}
Aggregations