Search in sources :

Example 1 with NestedFieldFilterScope

use of org.sonar.server.es.searchrequest.TopAggregationDefinition.NestedFieldFilterScope 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());
}
Also used : SimpleFieldFilterScope(org.sonar.server.es.searchrequest.TopAggregationDefinition.SimpleFieldFilterScope) NestedFieldFilterScope(org.sonar.server.es.searchrequest.TopAggregationDefinition.NestedFieldFilterScope) Test(org.junit.Test)

Example 2 with NestedFieldFilterScope

use of org.sonar.server.es.searchrequest.TopAggregationDefinition.NestedFieldFilterScope 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));
}
Also used : SimpleFieldFilterScope(org.sonar.server.es.searchrequest.TopAggregationDefinition.SimpleFieldFilterScope) NestedFieldFilterScope(org.sonar.server.es.searchrequest.TopAggregationDefinition.NestedFieldFilterScope) Test(org.junit.Test)

Example 3 with NestedFieldFilterScope

use of org.sonar.server.es.searchrequest.TopAggregationDefinition.NestedFieldFilterScope 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();
}
Also used : SimpleFieldFilterScope(org.sonar.server.es.searchrequest.TopAggregationDefinition.SimpleFieldFilterScope) NestedFieldFilterScope(org.sonar.server.es.searchrequest.TopAggregationDefinition.NestedFieldFilterScope) Test(org.junit.Test)

Example 4 with NestedFieldFilterScope

use of org.sonar.server.es.searchrequest.TopAggregationDefinition.NestedFieldFilterScope 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);
}
Also used : SimpleFieldFilterScope(org.sonar.server.es.searchrequest.TopAggregationDefinition.SimpleFieldFilterScope) RequestFiltersComputer.newAllFilters(org.sonar.server.es.searchrequest.RequestFiltersComputer.newAllFilters) AllFilters(org.sonar.server.es.searchrequest.RequestFiltersComputer.AllFilters) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) NestedFieldFilterScope(org.sonar.server.es.searchrequest.TopAggregationDefinition.NestedFieldFilterScope) Test(org.junit.Test)

Example 5 with NestedFieldFilterScope

use of org.sonar.server.es.searchrequest.TopAggregationDefinition.NestedFieldFilterScope in project sonarqube by SonarSource.

the class RequestFiltersComputerTest method filters_on_nestedField_of_sticky_TopAggregation_go_to_PostFilters_and_TopAgg_Filters_on_other_values_of_same_nestField.

@Test
public void filters_on_nestedField_of_sticky_TopAggregation_go_to_PostFilters_and_TopAgg_Filters_on_other_values_of_same_nestField() {
    String field1 = "field";
    String nestField = "nestedField";
    String nestField_value1 = "nestedField_value1";
    String nestField_value2 = "nestedField_value2";
    String nestField_value3 = "nestedField_value3";
    String nestField_value4 = "nestedField_value4";
    String nestField_value5 = "nestedField_value5";
    AllFilters allFilters = newAllFilters();
    // has topAggs and two filters
    NestedFieldFilterScope<String> filterScopeNestField_value1 = new NestedFieldFilterScope<>(field1, nestField, nestField_value1);
    NestedFieldTopAggregationDefinition<String> stickyTopAggField1 = newNestedFieldTopAggDef(field1, nestField, nestField_value1, STICKY);
    NestedFieldTopAggregationDefinition<String> nonStickyTopAggField1 = newNestedFieldTopAggDef(field1, nestField, nestField_value1, NON_STICKY);
    QueryBuilder filterField1_1 = newQuery();
    QueryBuilder filterField1_2 = newQuery();
    allFilters.addFilter("filter_field1_1", filterScopeNestField_value1, filterField1_1);
    allFilters.addFilter("filter_field1_2", filterScopeNestField_value1, filterField1_2);
    // has topAggs and one filter
    NestedFieldFilterScope<String> filterScopeNestField_value2 = new NestedFieldFilterScope<>(field1, nestField, nestField_value2);
    NestedFieldTopAggregationDefinition<String> stickyTopAggField2 = newNestedFieldTopAggDef(field1, nestField, nestField_value2, STICKY);
    NestedFieldTopAggregationDefinition<String> nonStickyTopAggField2 = newNestedFieldTopAggDef(field1, nestField, nestField_value2, NON_STICKY);
    QueryBuilder filterField2 = newQuery();
    allFilters.addFilter("filter_field2", filterScopeNestField_value2, filterField2);
    // has only non-sticky top-agg and one filter
    NestedFieldFilterScope<String> filterScopeField3 = new NestedFieldFilterScope<>(field1, nestField, nestField_value3);
    NestedFieldTopAggregationDefinition<String> nonStickyTopAggField3 = newNestedFieldTopAggDef(field1, nestField, nestField_value3, NON_STICKY);
    QueryBuilder filterField3 = newQuery();
    allFilters.addFilter("filter_field3", filterScopeField3, filterField3);
    // has one filter but no top agg
    NestedFieldFilterScope<String> filterScopeField4 = new NestedFieldFilterScope<>(field1, nestField, nestField_value4);
    QueryBuilder filterField4 = newQuery();
    allFilters.addFilter("filter_field4", filterScopeField4, filterField4);
    // has top-aggs by no filter
    String field5 = "field5";
    NestedFieldTopAggregationDefinition<String> stickyTopAggField5 = newNestedFieldTopAggDef(field1, nestField, nestField_value5, STICKY);
    NestedFieldTopAggregationDefinition<String> nonStickyTopAggField5 = newNestedFieldTopAggDef(field1, nestField, nestField_value5, NON_STICKY);
    Set<TopAggregationDefinition<?>> declaredTopAggregations = ImmutableSet.of(stickyTopAggField1, nonStickyTopAggField1, stickyTopAggField2, nonStickyTopAggField2, nonStickyTopAggField3, stickyTopAggField5, nonStickyTopAggField5);
    RequestFiltersComputer underTest = new RequestFiltersComputer(allFilters, declaredTopAggregations);
    assertThat(underTest.getQueryFilters()).contains(toBoolQuery(filterField3, filterField4));
    QueryBuilder[] postFilters = { filterField1_1, filterField1_2, filterField2 };
    assertThat(underTest.getPostFilters()).contains(toBoolQuery(postFilters));
    assertTopAggregationFilter(underTest, stickyTopAggField1, filterField2);
    assertTopAggregationFilter(underTest, nonStickyTopAggField1, postFilters);
    assertTopAggregationFilter(underTest, stickyTopAggField2, filterField1_1, filterField1_2);
    assertTopAggregationFilter(underTest, nonStickyTopAggField2, postFilters);
    assertTopAggregationFilter(underTest, nonStickyTopAggField3, postFilters);
    assertTopAggregationFilter(underTest, stickyTopAggField5, postFilters);
    assertTopAggregationFilter(underTest, nonStickyTopAggField5, postFilters);
}
Also used : RequestFiltersComputer.newAllFilters(org.sonar.server.es.searchrequest.RequestFiltersComputer.newAllFilters) AllFilters(org.sonar.server.es.searchrequest.RequestFiltersComputer.AllFilters) NestedFieldFilterScope(org.sonar.server.es.searchrequest.TopAggregationDefinition.NestedFieldFilterScope) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 NestedFieldFilterScope (org.sonar.server.es.searchrequest.TopAggregationDefinition.NestedFieldFilterScope)7 SimpleFieldFilterScope (org.sonar.server.es.searchrequest.TopAggregationDefinition.SimpleFieldFilterScope)5 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)3 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)3 AllFilters (org.sonar.server.es.searchrequest.RequestFiltersComputer.AllFilters)3 RequestFiltersComputer.newAllFilters (org.sonar.server.es.searchrequest.RequestFiltersComputer.newAllFilters)3