]> source.dussan.org Git - sonarqube.git/commitdiff
Fix sorting of issues - handle virtual line "zero"
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 24 Nov 2014 13:03:53 +0000 (14:03 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 24 Nov 2014 13:03:53 +0000 (14:03 +0100)
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java

index 2c99f8dd2e398a5d2ceeffbba42125a65ef93930..4579a245bdee2d6e34459df292db1e204af099f8 100644 (file)
@@ -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);
index 334785d408393da81aedc5d52c842250e5768ff8..d01828e0fd7c5e60f542485fc9fe96d987afcf5a 100644 (file)
@@ -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");