Search in sources :

Example 6 with NestedFieldFilterScope

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

the class RequestFiltersComputerTest method getTopAggregationFilters_returns_empty_on_sticky_nestedField_TopAgg_when_no_other_sticky_TopAgg.

@Test
public void getTopAggregationFilters_returns_empty_on_sticky_nestedField_TopAgg_when_no_other_sticky_TopAgg() {
    String field1 = "field";
    String nestField = "nestedField";
    String nestField_value1 = "nestedField_value1";
    String nestField_value2 = "nestedField_value2";
    AllFilters allFilters = newAllFilters();
    // has topAggs and two filters
    NestedFieldFilterScope<String> filterScopeField1 = 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", filterScopeField1, filterField1_1);
    allFilters.addFilter("filter_field1_2", filterScopeField1, filterField1_2);
    // has only non-sticky top-agg and one filter
    NestedFieldFilterScope<String> filterScopeField2 = new NestedFieldFilterScope<>(field1, nestField, nestField_value2);
    NestedFieldTopAggregationDefinition<String> nonStickyTopAggField2 = newNestedFieldTopAggDef(field1, nestField, nestField_value2, NON_STICKY);
    QueryBuilder filterField2 = newQuery();
    allFilters.addFilter("filter_field2", filterScopeField2, filterField2);
    Set<TopAggregationDefinition<?>> declaredTopAggregations = ImmutableSet.of(stickyTopAggField1, nonStickyTopAggField1, nonStickyTopAggField2);
    RequestFiltersComputer underTest = new RequestFiltersComputer(allFilters, declaredTopAggregations);
    assertThat(underTest.getQueryFilters()).contains(toBoolQuery(filterField2));
    QueryBuilder[] postFilters = { filterField1_1, filterField1_2 };
    assertThat(underTest.getPostFilters()).contains(toBoolQuery(postFilters));
    assertThat(underTest.getTopAggregationFilter(stickyTopAggField1)).isEmpty();
    assertTopAggregationFilter(underTest, nonStickyTopAggField1, postFilters);
    assertTopAggregationFilter(underTest, nonStickyTopAggField2, 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)

Example 7 with NestedFieldFilterScope

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

the class SimpleFieldFilterScopeTest method verify_equals.

@Test
public void verify_equals() {
    String fieldName1 = randomAlphabetic(11);
    String fieldName2 = randomAlphabetic(12);
    SimpleFieldFilterScope underTest = new SimpleFieldFilterScope(fieldName1);
    assertThat(underTest).isEqualTo(underTest).isEqualTo(new SimpleFieldFilterScope(fieldName1)).isNotNull().isNotEqualTo(new Object()).isNotEqualTo(new SimpleFieldFilterScope(fieldName2)).isNotEqualTo(new NestedFieldFilterScope<>(fieldName1, "foo", "bar")).isNotEqualTo(new NestedFieldFilterScope<>(fieldName2, "foo", "bar"));
}
Also used : SimpleFieldFilterScope(org.sonar.server.es.searchrequest.TopAggregationDefinition.SimpleFieldFilterScope) NestedFieldFilterScope(org.sonar.server.es.searchrequest.TopAggregationDefinition.NestedFieldFilterScope) 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