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);
}
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());
}
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()));
}
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);
}
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);
}
Aggregations