diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-11-24 14:03:53 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-11-24 14:03:53 +0100 |
commit | dc857ea1bae3c992ca0c364c8ec1888a00c4208a (patch) | |
tree | 7b9cbea9a48ca85314922a22195a1fb125c47743 | |
parent | c9c77b4babac770259dd5dc5b4d2077ab5f6f98d (diff) | |
download | sonarqube-dc857ea1bae3c992ca0c364c8ec1888a00c4208a.tar.gz sonarqube-dc857ea1bae3c992ca0c364c8ec1888a00c4208a.zip |
Fix sorting of issues - handle virtual line "zero"
-rw-r--r-- | server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java | 3 | ||||
-rw-r--r-- | server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java | 19 |
2 files changed, 12 insertions, 10 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 2c99f8dd2e3..4579a245bde 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 @@ -445,9 +445,12 @@ public class IssueIndex extends BaseIndex<Issue, IssueDto, String> { List<IndexField> fields = toIndexFields(sortField); for (IndexField field : fields) { FieldSortBuilder sortBuilder = SortBuilders.fieldSort(field.sortField()); + // line is optional. When missing, it means zero. if (asc != null && asc) { + sortBuilder.missing("_first"); sortBuilder.order(SortOrder.ASC); } else { + sortBuilder.missing("_last"); sortBuilder.order(SortOrder.DESC); } esSearch.addSort(sortBuilder); 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 334785d4083..d01828e0fd7 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 @@ -538,9 +538,9 @@ public class IssueIndexMediumTest { IssueQuery.Builder query = IssueQuery.builder().sort(IssueQuery.SORT_BY_CLOSE_DATE).asc(true); Result<Issue> result = index.search(query.build(), new QueryContext()); assertThat(result.getHits()).hasSize(3); - assertThat(result.getHits().get(0).closeDate()).isEqualTo(DateUtils.parseDate("2014-09-23")); - assertThat(result.getHits().get(1).closeDate()).isEqualTo(DateUtils.parseDate("2014-09-24")); - assertThat(result.getHits().get(2).closeDate()).isNull(); + assertThat(result.getHits().get(0).closeDate()).isNull(); + assertThat(result.getHits().get(1).closeDate()).isEqualTo(DateUtils.parseDate("2014-09-23")); + assertThat(result.getHits().get(2).closeDate()).isEqualTo(DateUtils.parseDate("2014-09-24")); query = IssueQuery.builder().sort(IssueQuery.SORT_BY_CLOSE_DATE).asc(false); result = index.search(query.build(), new QueryContext()); @@ -554,9 +554,9 @@ public class IssueIndexMediumTest { public void sort_by_file_and_line() throws Exception { db.issueDao().insert(session, // file Foo.java - IssueTesting.newDto(rule, file, project).setLine(20).setFilePath("src/Foo.java").setKee("FOO1"), - IssueTesting.newDto(rule, file, project).setLine(null).setFilePath("src/Foo.java").setKee("FOO3"), - IssueTesting.newDto(rule, file, project).setLine(25).setFilePath("src/Foo.java").setKee("FOO2"), + IssueTesting.newDto(rule, file, project).setLine(20).setFilePath("src/Foo.java").setKee("FOO2"), + IssueTesting.newDto(rule, file, project).setLine(null).setFilePath("src/Foo.java").setKee("FOO1"), + IssueTesting.newDto(rule, file, project).setLine(25).setFilePath("src/Foo.java").setKee("FOO3"), // file Bar.java IssueTesting.newDto(rule, file, project).setLine(9).setFilePath("src/Bar.java").setKee("BAR1"), @@ -581,10 +581,9 @@ public class IssueIndexMediumTest { query = IssueQuery.builder().sort(IssueQuery.SORT_BY_FILE_LINE).asc(false); result = index.search(query.build(), new QueryContext()); assertThat(result.getHits()).hasSize(6); - assertThat(result.getHits().get(0).key()).isEqualTo("FOO2"); - assertThat(result.getHits().get(1).key()).isEqualTo("FOO1"); - // nul line is on last. Could be improved. - assertThat(result.getHits().get(2).key()).isEqualTo("FOO3"); + assertThat(result.getHits().get(0).key()).isEqualTo("FOO3"); + assertThat(result.getHits().get(1).key()).isEqualTo("FOO2"); + assertThat(result.getHits().get(2).key()).isEqualTo("FOO1"); assertThat(result.getHits().get(3).key()).isEqualTo("BAR3"); assertThat(result.getHits().get(4).key()).isEqualTo("BAR2"); assertThat(result.getHits().get(5).key()).isEqualTo("BAR1"); |