Search in sources :

Example 1 with Facets

use of org.sonar.server.es.Facets in project sonarqube by SonarSource.

the class SearchAction method doHandle.

private SearchWsResponse doHandle(SearchWsRequest request, Request wsRequest) {
    // prepare the Elasticsearch request
    SearchOptions options = createSearchOptionsFromRequest(request);
    EnumSet<SearchAdditionalField> additionalFields = SearchAdditionalField.getFromRequest(request);
    IssueQuery query = issueQueryService.createFromRequest(request);
    // execute request
    SearchResult<IssueDoc> result = issueIndex.search(query, options);
    List<String> issueKeys = from(result.getDocs()).transform(IssueDocToKey.INSTANCE).toList();
    // load the additional information to be returned in response
    SearchResponseLoader.Collector collector = new SearchResponseLoader.Collector(additionalFields, issueKeys);
    collectLoggedInUser(collector);
    collectRequestParams(collector, request);
    Facets facets = null;
    if (!options.getFacets().isEmpty()) {
        facets = result.getFacets();
        // add missing values to facets. For example if assignee "john" and facet on "assignees" are requested, then
        // "john" should always be listed in the facet. If it is not present, then it is added with value zero.
        // This is a constraint from webapp UX.
        completeFacets(facets, request, wsRequest);
        collectFacets(collector, facets);
    }
    SearchResponseData data = searchResponseLoader.load(collector, facets);
    // format response
    // Filter and reorder facets according to the requested ordered names.
    // Must be done after loading of data as the "hidden" facet "debt"
    // can be used to get total debt.
    facets = reorderFacets(facets, options.getFacets());
    // FIXME allow long in Paging
    Paging paging = forPageIndex(options.getPage()).withPageSize(options.getLimit()).andTotal((int) result.getTotal());
    return searchResponseFormat.formatSearch(additionalFields, data, paging, facets);
}
Also used : IssueDoc(org.sonar.server.issue.index.IssueDoc) Facets(org.sonar.server.es.Facets) Paging(org.sonar.api.utils.Paging) SearchOptions(org.sonar.server.es.SearchOptions) IssueQuery(org.sonar.server.issue.IssueQuery)

Example 2 with Facets

use of org.sonar.server.es.Facets in project sonarqube by SonarSource.

the class ProjectMeasuresIndexTest method facet_reliability_rating.

@Test
public void facet_reliability_rating() {
    index(// 3 docs with rating A
    newDoc(RELIABILITY_RATING, 1d), newDoc(RELIABILITY_RATING, 1d), newDoc(RELIABILITY_RATING, 1d), // 2 docs with rating B
    newDoc(RELIABILITY_RATING, 2d), newDoc(RELIABILITY_RATING, 2d), // 4 docs with rating C
    newDoc(RELIABILITY_RATING, 3d), newDoc(RELIABILITY_RATING, 3d), newDoc(RELIABILITY_RATING, 3d), newDoc(RELIABILITY_RATING, 3d), // 2 docs with rating D
    newDoc(RELIABILITY_RATING, 4d), newDoc(RELIABILITY_RATING, 4d), // 5 docs with rating E
    newDoc(RELIABILITY_RATING, 5d), newDoc(RELIABILITY_RATING, 5d), newDoc(RELIABILITY_RATING, 5d), newDoc(RELIABILITY_RATING, 5d), newDoc(RELIABILITY_RATING, 5d));
    Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(RELIABILITY_RATING)).getFacets();
    assertThat(facets.get(RELIABILITY_RATING)).containsExactly(entry("1", 3L), entry("2", 2L), entry("3", 4L), entry("4", 2L), entry("5", 5L));
}
Also used : Facets(org.sonar.server.es.Facets) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 3 with Facets

use of org.sonar.server.es.Facets in project sonarqube by SonarSource.

the class ProjectMeasuresIndexTest method facet_security_rating.

@Test
public void facet_security_rating() {
    index(// 3 docs with rating A
    newDoc(SECURITY_RATING, 1.0d), newDoc(SECURITY_RATING, 1.0d), newDoc(SECURITY_RATING, 1.0d), // 2 docs with rating B
    newDoc(SECURITY_RATING, 2.0d), newDoc(SECURITY_RATING, 2.0d), // 4 docs with rating C
    newDoc(SECURITY_RATING, 3.0d), newDoc(SECURITY_RATING, 3.0d), newDoc(SECURITY_RATING, 3.0d), newDoc(SECURITY_RATING, 3.0d), // 2 docs with rating D
    newDoc(SECURITY_RATING, 4.0d), newDoc(SECURITY_RATING, 4.0d), // 5 docs with rating E
    newDoc(SECURITY_RATING, 5.0d), newDoc(SECURITY_RATING, 5.0d), newDoc(SECURITY_RATING, 5.0d), newDoc(SECURITY_RATING, 5.0d), newDoc(SECURITY_RATING, 5.0d));
    Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(SECURITY_RATING)).getFacets();
    assertThat(facets.get(SECURITY_RATING)).containsExactly(entry("1", 3L), entry("2", 2L), entry("3", 4L), entry("4", 2L), entry("5", 5L));
}
Also used : Facets(org.sonar.server.es.Facets) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 4 with Facets

use of org.sonar.server.es.Facets in project sonarqube by SonarSource.

the class ProjectMeasuresIndexTest method facet_maintainability_rating_contains_only_projects_authorized_for_user.

@Test
public void facet_maintainability_rating_contains_only_projects_authorized_for_user() throws Exception {
    // User can see these projects
    indexForUser(USER1, // 3 docs with rating A
    newDoc(MAINTAINABILITY_RATING, 1d), newDoc(MAINTAINABILITY_RATING, 1d), newDoc(MAINTAINABILITY_RATING, 1d), // 2 docs with rating B
    newDoc(MAINTAINABILITY_RATING, 2d), newDoc(MAINTAINABILITY_RATING, 2d));
    // User cannot see these projects
    indexForUser(USER2, // docs with rating C
    newDoc(MAINTAINABILITY_RATING, 3d), // docs with rating D
    newDoc(MAINTAINABILITY_RATING, 4d), // docs with rating E
    newDoc(MAINTAINABILITY_RATING, 5d));
    userSession.logIn(USER1);
    Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(MAINTAINABILITY_RATING)).getFacets();
    assertThat(facets.get(MAINTAINABILITY_RATING)).containsExactly(entry("1", 3L), entry("2", 2L), entry("3", 0L), entry("4", 0L), entry("5", 0L));
}
Also used : Facets(org.sonar.server.es.Facets) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 5 with Facets

use of org.sonar.server.es.Facets in project sonarqube by SonarSource.

the class ProjectMeasuresIndexTest method facet_maintainability_rating.

@Test
public void facet_maintainability_rating() {
    index(// 3 docs with rating A
    newDoc(MAINTAINABILITY_RATING, 1d), newDoc(MAINTAINABILITY_RATING, 1d), newDoc(MAINTAINABILITY_RATING, 1d), // 2 docs with rating B
    newDoc(MAINTAINABILITY_RATING, 2d), newDoc(MAINTAINABILITY_RATING, 2d), // 4 docs with rating C
    newDoc(MAINTAINABILITY_RATING, 3d), newDoc(MAINTAINABILITY_RATING, 3d), newDoc(MAINTAINABILITY_RATING, 3d), newDoc(MAINTAINABILITY_RATING, 3d), // 2 docs with rating D
    newDoc(MAINTAINABILITY_RATING, 4d), newDoc(MAINTAINABILITY_RATING, 4d), // 5 docs with rating E
    newDoc(MAINTAINABILITY_RATING, 5d), newDoc(MAINTAINABILITY_RATING, 5d), newDoc(MAINTAINABILITY_RATING, 5d), newDoc(MAINTAINABILITY_RATING, 5d), newDoc(MAINTAINABILITY_RATING, 5d));
    Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(MAINTAINABILITY_RATING)).getFacets();
    assertThat(facets.get(MAINTAINABILITY_RATING)).containsExactly(entry("1", 3L), entry("2", 2L), entry("3", 4L), entry("4", 2L), entry("5", 5L));
}
Also used : Facets(org.sonar.server.es.Facets) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Aggregations

Facets (org.sonar.server.es.Facets)58 SearchOptions (org.sonar.server.es.SearchOptions)51 Test (org.junit.Test)50 SearchResponse (org.elasticsearch.action.search.SearchResponse)14 ComponentDto (org.sonar.db.component.ComponentDto)10 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)3 Paging (org.sonar.api.utils.Paging)2 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Maps (com.google.common.collect.Maps)1 Ordering (com.google.common.collect.Ordering)1 Sets (com.google.common.collect.Sets)1 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 ZoneId (java.time.ZoneId)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1