use of org.sonar.server.es.searchrequest.TopAggregationDefinition.SimpleFieldFilterScope 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.TopAggregationDefinition.SimpleFieldFilterScope in project sonarqube by SonarSource.
the class SimpleFieldFilterScopeTest method verify_intersect.
@Test
public void verify_intersect() {
String fieldName1 = randomAlphabetic(11);
String fieldName2 = randomAlphabetic(12);
SimpleFieldFilterScope underTest = new SimpleFieldFilterScope(fieldName1);
assertThat(underTest.intersect(underTest)).isTrue();
assertThat(underTest.intersect(new SimpleFieldFilterScope(fieldName1))).isTrue();
assertThat(underTest.intersect(new SimpleFieldFilterScope(fieldName2))).isFalse();
assertThat(underTest.intersect(new NestedFieldFilterScope<>(fieldName1, "foo", "bar"))).isTrue();
assertThat(underTest.intersect(new NestedFieldFilterScope<>(fieldName2, "foo", "bar"))).isFalse();
}
use of org.sonar.server.es.searchrequest.TopAggregationDefinition.SimpleFieldFilterScope in project sonarqube by SonarSource.
the class SimpleFieldFilterScopeTest method verify_hashcode.
@Test
public void verify_hashcode() {
String fieldName1 = randomAlphabetic(11);
String fieldName2 = randomAlphabetic(12);
SimpleFieldFilterScope underTest = new SimpleFieldFilterScope(fieldName1);
assertThat(underTest.hashCode()).isEqualTo(underTest.hashCode()).isEqualTo(new SimpleFieldFilterScope(fieldName1).hashCode());
assertThat(underTest.hashCode()).isNotEqualTo(new Object().hashCode()).isNotEqualTo(new SimpleFieldFilterScope(fieldName2).hashCode()).isNotEqualTo(new NestedFieldFilterScope<>(fieldName1, "foo", "bar").hashCode()).isNotEqualTo(new NestedFieldFilterScope<>(fieldName1, "foo", "bar").hashCode());
}
use of org.sonar.server.es.searchrequest.TopAggregationDefinition.SimpleFieldFilterScope in project sonarqube by SonarSource.
the class NestedFieldFilterScopeTest method verify_equals.
@Test
public void verify_equals() {
String fieldName = randomAlphabetic(10);
String nestedFieldName = randomAlphabetic(11);
Object value = new Object();
String fieldName2 = randomAlphabetic(12);
String nestedFieldName2 = randomAlphabetic(13);
Object value2 = new Object();
NestedFieldFilterScope<Object> underTest = new NestedFieldFilterScope<>(fieldName, nestedFieldName, value);
assertThat(underTest).isEqualTo(underTest).isEqualTo(new NestedFieldFilterScope<>(fieldName, nestedFieldName, value)).isNotNull().isNotEqualTo(new Object()).isNotEqualTo(new NestedFieldFilterScope<>(fieldName2, nestedFieldName, value)).isNotEqualTo(new NestedFieldFilterScope<>(fieldName, nestedFieldName2, value)).isNotEqualTo(new NestedFieldFilterScope<>(fieldName, nestedFieldName, value2)).isNotEqualTo(new NestedFieldFilterScope<>(fieldName2, nestedFieldName2, value)).isNotEqualTo(new NestedFieldFilterScope<>(fieldName, nestedFieldName2, value2)).isNotEqualTo(new NestedFieldFilterScope<>(fieldName2, nestedFieldName, value2)).isNotEqualTo(new NestedFieldFilterScope<>(fieldName2, nestedFieldName2, value2)).isNotEqualTo(new SimpleFieldFilterScope(fieldName)).isNotEqualTo(new SimpleFieldFilterScope(fieldName2));
}
use of org.sonar.server.es.searchrequest.TopAggregationDefinition.SimpleFieldFilterScope in project sonarqube by SonarSource.
the class NestedFieldFilterScopeTest method verify_intersect.
@Test
public void verify_intersect() {
String fieldName = randomAlphabetic(10);
String nestedFieldName = randomAlphabetic(11);
Object value = new Object();
String fieldName2 = randomAlphabetic(12);
String nestedFieldName2 = randomAlphabetic(13);
Object value2 = new Object();
NestedFieldFilterScope<Object> underTest = new NestedFieldFilterScope<>(fieldName, nestedFieldName, value);
assertThat(underTest.intersect(underTest)).isTrue();
assertThat(underTest.intersect(new NestedFieldFilterScope<>(fieldName, nestedFieldName, value))).isTrue();
assertThat(underTest.intersect(new NestedFieldFilterScope<>(fieldName2, nestedFieldName, value))).isFalse();
assertThat(underTest.intersect(new NestedFieldFilterScope<>(fieldName, nestedFieldName2, value))).isFalse();
assertThat(underTest.intersect(new NestedFieldFilterScope<>(fieldName, nestedFieldName, value2))).isFalse();
assertThat(underTest.intersect(new NestedFieldFilterScope<>(fieldName2, nestedFieldName2, value))).isFalse();
assertThat(underTest.intersect(new NestedFieldFilterScope<>(fieldName, nestedFieldName2, value2))).isFalse();
assertThat(underTest.intersect(new NestedFieldFilterScope<>(fieldName2, nestedFieldName, value2))).isFalse();
assertThat(underTest.intersect(new NestedFieldFilterScope<>(fieldName2, nestedFieldName2, value2))).isFalse();
assertThat(underTest.intersect(new SimpleFieldFilterScope(fieldName))).isFalse();
assertThat(underTest.intersect(new SimpleFieldFilterScope(fieldName2))).isFalse();
}
Aggregations