use of org.sonar.server.es.searchrequest.RequestFiltersComputer.AllFilters in project sonarqube by SonarSource.
the class ProjectMeasuresIndex method createFilters.
private AllFilters createFilters(ProjectMeasuresQuery query) {
AllFilters filters = RequestFiltersComputer.newAllFilters();
filters.addFilter("__indexType", new SimpleFieldFilterScope(FIELD_INDEX_TYPE), termQuery(FIELD_INDEX_TYPE, TYPE_PROJECT_MEASURES.getName()));
if (!query.isIgnoreAuthorization()) {
filters.addFilter("__authorization", new SimpleFieldFilterScope("parent"), authorizationTypeSupport.createQueryFilter());
}
Multimap<String, MetricCriterion> metricCriterionMultimap = ArrayListMultimap.create();
query.getMetricCriteria().forEach(metricCriterion -> metricCriterionMultimap.put(metricCriterion.getMetricKey(), metricCriterion));
metricCriterionMultimap.asMap().forEach((key, value) -> {
BoolQueryBuilder metricFilters = boolQuery();
value.stream().map(ProjectMeasuresIndex::toQuery).forEach(metricFilters::must);
filters.addFilter(key, new NestedFieldFilterScope<>(FIELD_MEASURES, SUB_FIELD_MEASURES_KEY, key), metricFilters);
});
query.getQualityGateStatus().ifPresent(qualityGateStatus -> filters.addFilter(ALERT_STATUS_KEY, ALERT_STATUS.getFilterScope(), termQuery(FIELD_QUALITY_GATE_STATUS, QUALITY_GATE_STATUS.get(qualityGateStatus.name()))));
query.getProjectUuids().ifPresent(projectUuids -> filters.addFilter("ids", new SimpleFieldFilterScope("_id"), termsQuery("_id", projectUuids)));
query.getLanguages().ifPresent(languages -> filters.addFilter(FILTER_LANGUAGES, LANGUAGES.getFilterScope(), termsQuery(FIELD_LANGUAGES, languages)));
query.getTags().ifPresent(tags -> filters.addFilter(FIELD_TAGS, TAGS.getFilterScope(), termsQuery(FIELD_TAGS, tags)));
query.getQualifiers().ifPresent(qualifiers -> filters.addFilter(FIELD_QUALIFIER, new SimpleFieldFilterScope(FIELD_QUALIFIER), termsQuery(FIELD_QUALIFIER, qualifiers)));
query.getQueryText().map(ProjectsTextSearchQueryFactory::createQuery).ifPresent(queryBuilder -> filters.addFilter("textQuery", new SimpleFieldFilterScope(FIELD_NAME), queryBuilder));
return filters;
}
Aggregations