Search in sources :

Example 11 with AllFilters

use of org.sonar.server.es.searchrequest.RequestFiltersComputer.AllFilters 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 AllFilters

use of org.sonar.server.es.searchrequest.RequestFiltersComputer.AllFilters in project sonarqube by SonarSource.

the class RequestFiltersComputerTest method getTopAggregationFilters_return_empty_when_no_declared_sticky_topAggregation.

@Test
public void getTopAggregationFilters_return_empty_when_no_declared_sticky_topAggregation() {
    AllFilters allFilters = randomNonEmptyAllFilters();
    Set<TopAggregationDefinition<?>> atLeastOneNonStickyTopAggs = randomNonEmptyTopAggregations(() -> false);
    RequestFiltersComputer underTest = new RequestFiltersComputer(allFilters, atLeastOneNonStickyTopAggs);
    atLeastOneNonStickyTopAggs.forEach(topAgg -> assertThat(underTest.getTopAggregationFilter(topAgg)).isEmpty());
}
Also used : RequestFiltersComputer.newAllFilters(org.sonar.server.es.searchrequest.RequestFiltersComputer.newAllFilters) AllFilters(org.sonar.server.es.searchrequest.RequestFiltersComputer.AllFilters) Test(org.junit.Test)

Example 13 with AllFilters

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_topAggregation.

@Test
public void getQueryFilters_contains_all_filters_when_no_declared_topAggregation() {
    AllFilters allFilters = randomNonEmptyAllFilters();
    RequestFiltersComputer underTest = new RequestFiltersComputer(allFilters, Collections.emptySet());
    assertThat(underTest.getQueryFilters()).contains(toBoolQuery(allFilters.stream()));
}
Also used : RequestFiltersComputer.newAllFilters(org.sonar.server.es.searchrequest.RequestFiltersComputer.newAllFilters) AllFilters(org.sonar.server.es.searchrequest.RequestFiltersComputer.AllFilters) Test(org.junit.Test)

Example 14 with AllFilters

use of org.sonar.server.es.searchrequest.RequestFiltersComputer.AllFilters 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 15 with AllFilters

use of org.sonar.server.es.searchrequest.RequestFiltersComputer.AllFilters in project sonarqube by SonarSource.

the class IssueIndex method search.

public SearchResponse search(IssueQuery query, SearchOptions options) {
    SearchRequest requestBuilder = EsClient.prepareSearch(TYPE_ISSUE.getMainType());
    SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
    requestBuilder.source(sourceBuilder);
    configureSorting(query, sourceBuilder);
    configurePagination(options, sourceBuilder);
    configureRouting(query, options, requestBuilder);
    AllFilters allFilters = createAllFilters(query);
    RequestFiltersComputer filterComputer = newFilterComputer(options, allFilters);
    configureTopAggregations(query, options, sourceBuilder, allFilters, filterComputer);
    configureQuery(sourceBuilder, filterComputer);
    configureTopFilters(sourceBuilder, filterComputer);
    sourceBuilder.fetchSource(false).trackTotalHits(true);
    return client.search(requestBuilder);
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) AllFilters(org.sonar.server.es.searchrequest.RequestFiltersComputer.AllFilters) RequestFiltersComputer(org.sonar.server.es.searchrequest.RequestFiltersComputer) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder)

Aggregations

AllFilters (org.sonar.server.es.searchrequest.RequestFiltersComputer.AllFilters)16 RequestFiltersComputer.newAllFilters (org.sonar.server.es.searchrequest.RequestFiltersComputer.newAllFilters)12 Test (org.junit.Test)11 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)7 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)6 SimpleFieldFilterScope (org.sonar.server.es.searchrequest.TopAggregationDefinition.SimpleFieldFilterScope)6 NestedFieldFilterScope (org.sonar.server.es.searchrequest.TopAggregationDefinition.NestedFieldFilterScope)3 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)2 RequestFiltersComputer (org.sonar.server.es.searchrequest.RequestFiltersComputer)2 SearchRequest (org.elasticsearch.action.search.SearchRequest)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 SearchIdResult (org.sonar.server.es.SearchIdResult)1 MetricCriterion (org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion)1