use of org.sonar.server.measure.index.ProjectMeasuresIndexDefinition.FIELD_MEASURES in project sonarqube by SonarSource.
the class ProjectMeasuresIndex method createFilters.
private Map<String, QueryBuilder> createFilters(ProjectMeasuresQuery query) {
Map<String, QueryBuilder> filters = new HashMap<>();
filters.put("__authorization", authorizationTypeSupport.createQueryFilter());
Multimap<String, MetricCriterion> metricCriterionMultimap = ArrayListMultimap.create();
query.getMetricCriteria().forEach(metricCriterion -> metricCriterionMultimap.put(metricCriterion.getMetricKey(), metricCriterion));
metricCriterionMultimap.asMap().entrySet().forEach(entry -> {
BoolQueryBuilder metricFilters = boolQuery();
entry.getValue().stream().map(criterion -> nestedQuery(FIELD_MEASURES, boolQuery().filter(termQuery(FIELD_MEASURES_KEY, criterion.getMetricKey())).filter(toValueQuery(criterion)))).forEach(metricFilters::must);
filters.put(entry.getKey(), metricFilters);
});
query.getQualityGateStatus().ifPresent(qualityGateStatus -> filters.put(ALERT_STATUS_KEY, termQuery(FIELD_QUALITY_GATE_STATUS, QUALITY_GATE_STATUS.get(qualityGateStatus.name()))));
query.getProjectUuids().ifPresent(projectUuids -> filters.put("ids", termsQuery("_id", projectUuids)));
query.getLanguages().ifPresent(languages -> filters.put(FILTER_LANGUAGES, termsQuery(FIELD_LANGUAGES, languages)));
query.getOrganizationUuid().ifPresent(organizationUuid -> filters.put(FIELD_ORGANIZATION_UUID, termQuery(FIELD_ORGANIZATION_UUID, organizationUuid)));
query.getTags().ifPresent(tags -> filters.put(FIELD_TAGS, termsQuery(FIELD_TAGS, tags)));
createTextQueryFilter(query).ifPresent(queryBuilder -> filters.put("textQuery", queryBuilder));
return filters;
}
Aggregations