Search in sources :

Example 11 with SimpleFieldFilterScope

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

the class RequestFiltersComputerTest method getTopAggregationFilters_returns_empty_on_sticky_field_TopAgg_when_no_other_sticky_TopAgg.

@Test
public void getTopAggregationFilters_returns_empty_on_sticky_field_TopAgg_when_no_other_sticky_TopAgg() {
    AllFilters allFilters = newAllFilters();
    // has topAggs and two filters
    String field1 = "field1";
    SimpleFieldFilterScope filterScopeField1 = new SimpleFieldFilterScope(field1);
    SimpleFieldTopAggregationDefinition stickyTopAggField1 = new SimpleFieldTopAggregationDefinition(field1, STICKY);
    SimpleFieldTopAggregationDefinition nonStickyTopAggField1 = new SimpleFieldTopAggregationDefinition(field1, 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
    String field2 = "field2";
    SimpleFieldFilterScope filterScopeField2 = new SimpleFieldFilterScope(field2);
    SimpleFieldTopAggregationDefinition nonStickyTopAggField2 = new SimpleFieldTopAggregationDefinition(field2, 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 : 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) Test(org.junit.Test)

Example 12 with SimpleFieldFilterScope

use of org.sonar.server.es.searchrequest.TopAggregationDefinition.SimpleFieldFilterScope 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)

Example 13 with SimpleFieldFilterScope

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

the class SimpleFieldFilterScopeTest method getFieldName.

@Test
public void getFieldName() {
    String fieldName = randomAlphabetic(12);
    SimpleFieldFilterScope underTest = new SimpleFieldFilterScope(fieldName);
    assertThat(underTest.getFieldName()).isEqualTo(fieldName);
}
Also used : SimpleFieldFilterScope(org.sonar.server.es.searchrequest.TopAggregationDefinition.SimpleFieldFilterScope) Test(org.junit.Test)

Example 14 with SimpleFieldFilterScope

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

the class RequestFiltersComputerTest method getQueryFilters_returns_empty_when_all_filters_have_sticky_TopAggs.

@Test
public void getQueryFilters_returns_empty_when_all_filters_have_sticky_TopAggs() {
    AllFilters allFilters = newAllFilters();
    // has topAggs and two filters
    String field1 = "field1";
    SimpleFieldFilterScope filterScopeField1 = new SimpleFieldFilterScope(field1);
    SimpleFieldTopAggregationDefinition stickyTopAggField1 = new SimpleFieldTopAggregationDefinition(field1, STICKY);
    SimpleFieldTopAggregationDefinition nonStickyTopAggField1 = new SimpleFieldTopAggregationDefinition(field1, 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 sticky top-agg and one filter
    String field2 = "field2";
    SimpleFieldFilterScope filterScopeField2 = new SimpleFieldFilterScope(field2);
    SimpleFieldTopAggregationDefinition stickyTopAggField2 = new SimpleFieldTopAggregationDefinition(field2, STICKY);
    QueryBuilder filterField2 = newQuery();
    allFilters.addFilter("filter_field2", filterScopeField2, filterField2);
    Set<TopAggregationDefinition<?>> declaredTopAggregations = ImmutableSet.of(stickyTopAggField1, nonStickyTopAggField1, stickyTopAggField2);
    RequestFiltersComputer underTest = new RequestFiltersComputer(allFilters, declaredTopAggregations);
    assertThat(underTest.getQueryFilters()).isEmpty();
    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);
}
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) Test(org.junit.Test)

Example 15 with SimpleFieldFilterScope

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

the class IssueIndex method addCommonComponentRelatedFilters.

private static void addCommonComponentRelatedFilters(IssueQuery query, AllFilters filters) {
    filters.addFilter(FIELD_ISSUE_COMPONENT_UUID, new SimpleFieldFilterScope(FIELD_ISSUE_COMPONENT_UUID), createTermsFilter(FIELD_ISSUE_COMPONENT_UUID, query.componentUuids()));
    if (!Boolean.TRUE.equals(query.onComponentOnly())) {
        filters.addFilter(FIELD_ISSUE_PROJECT_UUID, new SimpleFieldFilterScope(FIELD_ISSUE_PROJECT_UUID), createTermsFilter(FIELD_ISSUE_PROJECT_UUID, query.projectUuids()));
        filters.addFilter("__module", new SimpleFieldFilterScope(FIELD_ISSUE_MODULE_PATH), createTermsFilter(FIELD_ISSUE_MODULE_PATH, query.moduleRootUuids()));
        filters.addFilter(FIELD_ISSUE_MODULE_UUID, new SimpleFieldFilterScope(FIELD_ISSUE_MODULE_UUID), createTermsFilter(FIELD_ISSUE_MODULE_UUID, query.moduleUuids()));
        filters.addFilter(FIELD_ISSUE_DIRECTORY_PATH, new SimpleFieldFilterScope(FIELD_ISSUE_DIRECTORY_PATH), createTermsFilter(FIELD_ISSUE_DIRECTORY_PATH, query.directories()));
        filters.addFilter(FIELD_ISSUE_FILE_PATH, new SimpleFieldFilterScope(FIELD_ISSUE_FILE_PATH), createTermsFilter(FIELD_ISSUE_FILE_PATH, query.files()));
    }
}
Also used : SimpleFieldFilterScope(org.sonar.server.es.searchrequest.TopAggregationDefinition.SimpleFieldFilterScope)

Aggregations

SimpleFieldFilterScope (org.sonar.server.es.searchrequest.TopAggregationDefinition.SimpleFieldFilterScope)16 Test (org.junit.Test)10 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)7 AllFilters (org.sonar.server.es.searchrequest.RequestFiltersComputer.AllFilters)6 NestedFieldFilterScope (org.sonar.server.es.searchrequest.TopAggregationDefinition.NestedFieldFilterScope)5 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)4 RequestFiltersComputer.newAllFilters (org.sonar.server.es.searchrequest.RequestFiltersComputer.newAllFilters)4 PeriodStart (org.sonar.server.issue.index.IssueQuery.PeriodStart)1 MetricCriterion (org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion)1