Support count=0 to retrieve totalResults only

Change-Id: Ibc64fca72d2e8464992fb05dd23507a099be1349
diff --git a/Changes b/Changes
index 6e363e0..150340f 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,4 @@
-0.58.6 2019-07-17
+0.58.6 2019-08-28
     - [bugfix] Updated cache loading (fixed #55) (diewald, margaretha)
     - [bugfix] Introduce left match cutting so that
       in matchinfo with expandToContext cutting won't
@@ -10,6 +10,8 @@
     - [bugfix] Do not optimize %+w1:1 to be a treated like /+w1:1
       (diewald)
     - [cleanup] Added a CQL AND query test (margaretha)  
+    - [feature] Accept count=0 to only retrieve totalResults
+      (diewald)
 
 0.58.5 2019-03-18
     - [bugfix] Fix bug where duplicate keys occured in
diff --git a/src/main/java/de/ids_mannheim/korap/KrillMeta.java b/src/main/java/de/ids_mannheim/korap/KrillMeta.java
index 8ce45c0..eddafd8 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillMeta.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillMeta.java
@@ -200,7 +200,7 @@
 
 
     public KrillMeta setCount (short value) {
-        if (value > 0)
+        if (value >= 0)
             this.count = (value <= this.countMax) ? value : this.countMax;
         return this;
     };
diff --git a/src/main/java/de/ids_mannheim/korap/response/Result.java b/src/main/java/de/ids_mannheim/korap/response/Result.java
index 0dabb24..32b3cfe 100644
--- a/src/main/java/de/ids_mannheim/korap/response/Result.java
+++ b/src/main/java/de/ids_mannheim/korap/response/Result.java
@@ -90,7 +90,7 @@
         this.serialQuery = query;
         this.startIndex = startIndex;
         this.itemsPerPage = (itemsPerPage > ITEMS_PER_PAGE_MAX
-                || itemsPerPage < 1) ? ITEMS_PER_PAGE : itemsPerPage;
+                || itemsPerPage < 0) ? ITEMS_PER_PAGE : itemsPerPage;
         this.context = context;
     };
 
diff --git a/src/test/java/de/ids_mannheim/korap/search/TestKrill.java b/src/test/java/de/ids_mannheim/korap/search/TestKrill.java
index fda521e..c407cce 100644
--- a/src/test/java/de/ids_mannheim/korap/search/TestKrill.java
+++ b/src/test/java/de/ids_mannheim/korap/search/TestKrill.java
@@ -30,6 +30,7 @@
 
 @RunWith(JUnit4.class)
 public class TestKrill {
+
     @Test
     public void searchCount () {
         Krill k = new Krill(new QueryBuilder("field1").seg("a").with("b"));
@@ -45,9 +46,10 @@
         assertEquals(meta.getCount(), 20);
         meta.setCount(500);
         assertEquals(meta.getCount(), meta.getCountMax());
+        meta.setCount(0);
+        assertEquals(meta.getCount(), 0);
     };
 
-
     @Test
     public void searchStartIndex () {
         Krill k = new Krill(new QueryBuilder("field1").seg("a").with("b"));
@@ -103,6 +105,7 @@
 
         Result kr = ks.apply(ki);
         assertEquals(kr.getTotalResults(), 6);
+        assertEquals(kr.getMatches().size(), 1);
         assertEquals(kr.getMatch(0).getSnippetBrackets(),
                 "... dem [[Buchstaben]] A ...");
 
@@ -113,6 +116,14 @@
         assertEquals(1, res.at("/meta/context/left/1").asInt());
         assertEquals("token", res.at("/meta/context/right/0").asText());
         assertEquals(1, res.at("/meta/context/right/1").asInt());
+
+        // Handle count=0 correctly
+        meta = ks.getMeta();
+        meta.setCount(0);
+        kr = ks.apply(ki);
+        assertEquals(kr.getTotalResults(), 6);
+        assertEquals(kr.getItemsPerPage(), 0);
+        assertEquals(kr.getMatches().size(), 0);
     };
 
 
@@ -185,7 +196,7 @@
                 getClass().getResource("/queries/metaquery6.jsonld").getFile());
         ks = new Krill(json);
         kr = ks.apply(ki);
-        assertEquals(kr.getTotalResults(), 1);
+        assertEquals(kr.getTotalResults(), 1);        
     };