From 19a55559d19158b88fa5ce6d3ed1ae975132f8bd Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lievremont Date: Mon, 9 Feb 2015 14:52:29 +0100 Subject: [PATCH] SONAR-6137 Handle lower bound for createdAt facet when no document match --- .../org/sonar/server/issue/index/IssueIndex.java | 7 ++++++- .../server/issue/index/IssueIndexMediumTest.java | 16 ++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java index 51209878598..7b7b11590c2 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java @@ -495,7 +495,12 @@ public class IssueIndex extends BaseIndex { } esRequest.addAggregation(AggregationBuilders.min(facetNameAndField).field(facetNameAndField)); Min minValue = esRequest.get().getAggregations().get(facetNameAndField); - return (long) minValue.getValue(); + Double actualValue = minValue.getValue(); + if (actualValue.isInfinite()) { + return Long.MIN_VALUE; + } else { + return actualValue.longValue(); + } } private AggregationBuilder createAssigneesFacet(IssueQuery query, Map filters, QueryBuilder queryBuilder) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java index 8f55539d654..acb942e098a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java @@ -44,12 +44,7 @@ import org.sonar.server.view.index.ViewIndexer; import javax.annotation.Nullable; -import java.util.Arrays; -import java.util.Date; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import static com.google.common.collect.Lists.newArrayList; import static org.assertj.core.api.Assertions.assertThat; @@ -750,6 +745,15 @@ public class IssueIndexMediumTest { entry("2016-01-01T01:00:00+0000", 0L)); } + @Test + public void facet_on_created_at_without_issues() throws Exception { + SearchOptions SearchOptions = new SearchOptions().addFacets("createdAt"); + + Map createdAt = index.search(IssueQuery.builder().build(), + SearchOptions).getFacets().get("createdAt"); + assertThat(createdAt).isEmpty(); + } + protected SearchOptions fixtureForCreatedAtFacet() { ComponentDto project = ComponentTesting.newProjectDto(); ComponentDto file = ComponentTesting.newFileDto(project); -- 2.39.5