Search in sources :

Example 16 with AllFilters

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;
}
Also used : SimpleFieldFilterScope(org.sonar.server.es.searchrequest.TopAggregationDefinition.SimpleFieldFilterScope) MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) AllFilters(org.sonar.server.es.searchrequest.RequestFiltersComputer.AllFilters)

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