Short circuit count=0 and cutoff=true

Change-Id: If46ffeff677e8d28fedfd24a664d6a7833f810a0
diff --git a/Changes b/Changes
index a49fa75..e72713d 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,7 @@
+0.63.3 2024-09-24
+    - [performance] Improve short circuit on count=0 and
+      cutoff=true (diewald)
+
 0.63.2 2024-08-02
     - [bugfix] Fix empty DocIdSetIterator (margaretha)
     - [bugfix] Don't throw warnings on expansion failure (diewald)
diff --git a/pom.xml b/pom.xml
index 50878c1..dc8930e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -35,7 +35,7 @@
 
   <groupId>de.ids-mannheim.korap.krill</groupId>
   <artifactId>Krill</artifactId>
-  <version>0.63.2</version>
+  <version>0.63.3</version>
   <packaging>jar</packaging>
 
   <name>Krill</name>
diff --git a/src/main/java/de/ids_mannheim/korap/KrillIndex.java b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
index 9073810..43041db 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
@@ -1423,6 +1423,12 @@
                 return kr;
         };
 
+        if (cutoff && count == 0) {
+            kr.setTotalResults(-1);
+            kr.setTotalResources(-1);
+            return kr;
+        };
+
         // Collect matches from atomic readers
         final ArrayList<Match> atomicMatches = new ArrayList<Match>(
                 kr.getItemsPerPage());
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 0b34e56..fe4adcc 100644
--- a/src/test/java/de/ids_mannheim/korap/search/TestKrill.java
+++ b/src/test/java/de/ids_mannheim/korap/search/TestKrill.java
@@ -136,9 +136,20 @@
         assertEquals(kr.getItemsPerPage(), 0);
         assertEquals(kr.getMatches().size(), 0);
 
+        // Handle count=0 correctly
+        meta = ks.getMeta();
+        meta.setCount(0);
+        meta.setCutOff(true);
+
+        kr = ks.apply(ki);
+        assertEquals(kr.getTotalResults(), -1);
+        assertEquals(kr.getItemsPerPage(), 0);
+        assertEquals(kr.getMatches().size(), 0);
+        
         // Handle tokens=true and
         // snippet=false correctly
         meta = ks.getMeta();
+        meta.setCutOff(false);
         meta.setCount(1);
         meta.setTokens(true);
         meta.setSnippets(false);