Search in sources :

Example 1 with IssueQuery

use of org.sonar.server.issue.IssueQuery 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 IssueQuery

use of org.sonar.server.issue.IssueQuery in project sonarqube by SonarSource.

the class IssueIndexTest method facet_on_created_at_with_less_than_20_days.

@Test
public void facet_on_created_at_with_less_than_20_days() {
    SearchOptions options = fixtureForCreatedAtFacet();
    IssueQuery query = IssueQuery.builder().createdAfter(parseDateTime("2014-09-01T00:00:00+0100")).createdBefore(parseDateTime("2014-09-08T00:00:00+0100")).checkAuthorization(false).build();
    SearchResult<IssueDoc> result = underTest.search(query, options);
    Map<String, Long> buckets = result.getFacets().get("createdAt");
    assertThat(buckets).containsOnly(entry("2014-08-31T01:00:00+0000", 0L), entry("2014-09-01T01:00:00+0000", 2L), entry("2014-09-02T01:00:00+0000", 1L), entry("2014-09-03T01:00:00+0000", 0L), entry("2014-09-04T01:00:00+0000", 0L), entry("2014-09-05T01:00:00+0000", 1L), entry("2014-09-06T01:00:00+0000", 0L), entry("2014-09-07T01:00:00+0000", 0L));
}
Also used : SearchOptions(org.sonar.server.es.SearchOptions) IssueQuery(org.sonar.server.issue.IssueQuery) Test(org.junit.Test)

Aggregations

SearchOptions (org.sonar.server.es.SearchOptions)2 IssueQuery (org.sonar.server.issue.IssueQuery)2 Test (org.junit.Test)1 Paging (org.sonar.api.utils.Paging)1 Facets (org.sonar.server.es.Facets)1 IssueDoc (org.sonar.server.issue.index.IssueDoc)1