use of org.sonar.server.es.searchrequest.RequestFiltersComputer.AllFilters in project sonarqube by SonarSource.
the class ProjectMeasuresIndex method search.
public SearchIdResult<String> search(ProjectMeasuresQuery query, SearchOptions searchOptions) {
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().fetchSource(false).trackTotalHits(true).from(searchOptions.getOffset()).size(searchOptions.getLimit());
AllFilters allFilters = createFilters(query);
RequestFiltersComputer filtersComputer = createFiltersComputer(searchOptions, allFilters);
addFacets(searchSourceBuilder, searchOptions, filtersComputer, query);
addSort(query, searchSourceBuilder);
filtersComputer.getQueryFilters().ifPresent(searchSourceBuilder::query);
filtersComputer.getPostFilters().ifPresent(searchSourceBuilder::postFilter);
SearchResponse response = client.search(EsClient.prepareSearch(TYPE_PROJECT_MEASURES.getMainType()).source(searchSourceBuilder));
return new SearchIdResult<>(response, id -> id, system2.getDefaultTimeZone().toZoneId());
}
use of org.sonar.server.es.searchrequest.RequestFiltersComputer.AllFilters 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);
}
use of org.sonar.server.es.searchrequest.RequestFiltersComputer.AllFilters in project sonarqube by SonarSource.
the class RequestFiltersComputerTest method filters_on_field_of_sticky_TopAggregation_go_to_PostFilters_and_TopAgg_Filters_on_other_fields.
@Test
public void filters_on_field_of_sticky_TopAggregation_go_to_PostFilters_and_TopAgg_Filters_on_other_fields() {
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 topAggs and one filter
String field2 = "field2";
SimpleFieldFilterScope filterScopeField2 = new SimpleFieldFilterScope(field2);
SimpleFieldTopAggregationDefinition stickyTopAggField2 = new SimpleFieldTopAggregationDefinition(field2, STICKY);
SimpleFieldTopAggregationDefinition nonStickyTopAggField2 = new SimpleFieldTopAggregationDefinition(field2, NON_STICKY);
QueryBuilder filterField2 = newQuery();
allFilters.addFilter("filter_field2", filterScopeField2, filterField2);
// has only non-sticky top-agg and one filter
String field3 = "field3";
SimpleFieldFilterScope filterScopeField3 = new SimpleFieldFilterScope(field3);
SimpleFieldTopAggregationDefinition nonStickyTopAggField3 = new SimpleFieldTopAggregationDefinition(field3, NON_STICKY);
QueryBuilder filterField3 = newQuery();
allFilters.addFilter("filter_field3", filterScopeField3, filterField3);
// has one filter but no top agg
String field4 = "field4";
SimpleFieldFilterScope filterScopeField4 = new SimpleFieldFilterScope(field4);
QueryBuilder filterField4 = newQuery();
allFilters.addFilter("filter_field4", filterScopeField4, filterField4);
// has top-aggs by no filter
String field5 = "field5";
SimpleFieldTopAggregationDefinition stickyTopAggField5 = new SimpleFieldTopAggregationDefinition(field5, STICKY);
SimpleFieldTopAggregationDefinition nonStickyTopAggField5 = new SimpleFieldTopAggregationDefinition(field5, 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);
}
use of org.sonar.server.es.searchrequest.RequestFiltersComputer.AllFilters in project sonarqube by SonarSource.
the class RequestFiltersComputerTest method randomNonEmptyAllFilters.
private static AllFilters randomNonEmptyAllFilters() {
AllFilters res = newAllFilters();
IntStream.range(0, 1 + RANDOM.nextInt(22)).forEach(i -> res.addFilter("filter_" + i, mock(FilterScope.class), newQuery()));
return res;
}
use of org.sonar.server.es.searchrequest.RequestFiltersComputer.AllFilters 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);
}
Aggregations