use of org.sonar.server.es.Facets in project sonarqube by SonarSource.
the class IssueIndexFacetsTest method facet_on_created_at_with_more_than_20_months.
@Test
public void facet_on_created_at_with_more_than_20_months() {
SearchOptions options = fixtureForCreatedAtFacet();
SearchResponse result = underTest.search(IssueQuery.builder().createdAfter(parseDateTime("2011-01-01T00:00:00+0100")).createdBefore(parseDateTime("2016-01-01T00:00:00+0100")).build(), options);
Map<String, Long> createdAt = new Facets(result, system2.getDefaultTimeZone().toZoneId()).get("createdAt");
assertThat(createdAt).containsOnly(entry("2010-01-01", 0L), entry("2011-01-01", 1L), entry("2012-01-01", 0L), entry("2013-01-01", 0L), entry("2014-01-01", 5L), entry("2015-01-01", 1L));
}
use of org.sonar.server.es.Facets in project sonarqube by SonarSource.
the class IssueIndexFacetsTest method facet_on_created_at_without_issues.
@Test
public void facet_on_created_at_without_issues() {
SearchOptions searchOptions = new SearchOptions().addFacets("createdAt");
SearchResponse result = underTest.search(IssueQuery.builder().build(), searchOptions);
Map<String, Long> createdAt = new Facets(result, system2.getDefaultTimeZone().toZoneId()).get("createdAt");
assertThat(createdAt).isNull();
}
use of org.sonar.server.es.Facets in project sonarqube by SonarSource.
the class IssueIndexFacetsTest method assertThatFacetHasOnly.
@SafeVarargs
private final void assertThatFacetHasOnly(IssueQuery.Builder query, String facet, Map.Entry<String, Long>... expectedEntries) {
SearchResponse result = underTest.search(query.build(), new SearchOptions().addFacets(singletonList(facet)));
Facets facets = new Facets(result, system2.getDefaultTimeZone().toZoneId());
assertThat(facets.getNames()).containsOnly(facet, "effort");
assertThat(facets.get(facet)).containsOnly(expectedEntries);
}
use of org.sonar.server.es.Facets in project sonarqube by SonarSource.
the class SearchAction method doHandle.
private SearchWsResponse doHandle(SearchRequest request) {
// prepare the Elasticsearch request
SearchOptions options = createSearchOptionsFromRequest(request);
EnumSet<SearchAdditionalField> additionalFields = SearchAdditionalField.getFromRequest(request);
IssueQuery query = issueQueryFactory.create(request);
Set<String> facetsRequiringProjectParameter = options.getFacets().stream().filter(FACETS_REQUIRING_PROJECT::contains).collect(toSet());
checkArgument(facetsRequiringProjectParameter.isEmpty() || (!query.projectUuids().isEmpty()), "Facet(s) '%s' require to also filter by project", String.join(",", facetsRequiringProjectParameter));
// execute request
SearchResponse result = issueIndex.search(query, options);
List<String> issueKeys = Arrays.stream(result.getHits().getHits()).map(SearchHit::getId).collect(MoreCollectors.toList(result.getHits().getHits().length));
// load the additional information to be returned in response
SearchResponseLoader.Collector collector = new SearchResponseLoader.Collector(issueKeys);
collectLoggedInUser(collector);
collectRequestParams(collector, request);
Facets facets = new Facets(result, Optional.ofNullable(query.timeZone()).orElse(system2.getDefaultTimeZone().toZoneId()));
if (!options.getFacets().isEmpty()) {
// 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, query);
collectFacets(collector, facets);
}
SearchResponseData preloadedData = new SearchResponseData(emptyList());
preloadedData.addRules(List.copyOf(query.rules()));
SearchResponseData data = searchResponseLoader.load(preloadedData, collector, additionalFields, facets);
// FIXME allow long in Paging
Paging paging = forPageIndex(options.getPage()).withPageSize(options.getLimit()).andTotal((int) getTotalHits(result).value);
return searchResponseFormat.formatSearch(additionalFields, data, paging, facets);
}
use of org.sonar.server.es.Facets in project sonarqube by SonarSource.
the class ProjectMeasuresIndexTest method facet_maintainability_rating_is_sticky.
@Test
public void facet_maintainability_rating_is_sticky() {
index(// docs with rating A
newDoc(MAINTAINABILITY_RATING, 1d, NCLOC, 100d, COVERAGE, 0d), newDoc(MAINTAINABILITY_RATING, 1d, NCLOC, 200d, COVERAGE, 0d), newDoc(MAINTAINABILITY_RATING, 1d, NCLOC, 999d, COVERAGE, 0d), // docs with rating B
newDoc(MAINTAINABILITY_RATING, 2d, NCLOC, 2000d, COVERAGE, 0d), newDoc(MAINTAINABILITY_RATING, 2d, NCLOC, 5000d, COVERAGE, 0d), // docs with rating C
newDoc(MAINTAINABILITY_RATING, 3d, NCLOC, 20000d, COVERAGE, 0d), newDoc(MAINTAINABILITY_RATING, 3d, NCLOC, 30000d, COVERAGE, 0d), newDoc(MAINTAINABILITY_RATING, 3d, NCLOC, 40000d, COVERAGE, 0d), newDoc(MAINTAINABILITY_RATING, 3d, NCLOC, 50000d, COVERAGE, 0d), // docs with rating D
newDoc(MAINTAINABILITY_RATING, 4d, NCLOC, 120000d, COVERAGE, 0d), // docs with rating E
newDoc(MAINTAINABILITY_RATING, 5d, NCLOC, 600000d, COVERAGE, 40d), newDoc(MAINTAINABILITY_RATING, 5d, NCLOC, 700000d, COVERAGE, 50d), newDoc(MAINTAINABILITY_RATING, 5d, NCLOC, 800000d, COVERAGE, 60d));
Facets facets = underTest.search(new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion(MAINTAINABILITY_RATING, Operator.LT, 3d)).addMetricCriterion(new MetricCriterion(COVERAGE, Operator.LT, 30d)), new SearchOptions().addFacets(MAINTAINABILITY_RATING, NCLOC)).getFacets();
// Sticky facet on maintainability rating does not take into account maintainability rating filter
assertThat(facets.get(MAINTAINABILITY_RATING)).containsExactly(entry("1", 3L), entry("2", 2L), entry("3", 4L), entry("4", 1L), entry("5", 0L));
// But facet on ncloc does well take into into filters
assertThat(facets.get(NCLOC)).containsExactly(entry("*-1000.0", 3L), entry("1000.0-10000.0", 2L), entry("10000.0-100000.0", 0L), entry("100000.0-500000.0", 0L), entry("500000.0-*", 0L));
}
Aggregations