Fixed caching VC with negation query.

Change-Id: I4296cdc6d20af36a641bb34ae65b5e8b02661453
diff --git a/src/main/java/de/ids_mannheim/korap/collection/ToCacheVCFilter.java b/src/main/java/de/ids_mannheim/korap/collection/ToCacheVCFilter.java
index 7c8a815..b0f3b59 100644
--- a/src/main/java/de/ids_mannheim/korap/collection/ToCacheVCFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/collection/ToCacheVCFilter.java
@@ -47,16 +47,21 @@
         FixedBitSet bitset = new FixedBitSet(maxDoc);
 
         if (docIdSet == null) {
-            if (this.cbi != null) {
-                bitset.clear(0, bitset.length());
+            if (cbi.isNegative()) {
+                bitset.set(0, maxDoc);
             }
             else {
-                bitset.set(0, bitset.length());
-            };
+                bitset.clear(0, maxDoc);
+            }
         }
         else {
             bitset.or(docIdSet.iterator());
+            if (cbi.isNegative()){
+                bitset.flip(0, maxDoc);
+            }
         }
+        
+        
 
         docIdMap.put(context.hashCode(), new DocBits(bitset.getBits()));
         CachedVCData cachedVCData = new CachedVCData(new HashMap<>(docIdMap));
diff --git a/src/test/java/de/ids_mannheim/korap/collection/TestVCCaching.java b/src/test/java/de/ids_mannheim/korap/collection/TestVCCaching.java
index 795a6d3..632a194 100644
--- a/src/test/java/de/ids_mannheim/korap/collection/TestVCCaching.java
+++ b/src/test/java/de/ids_mannheim/korap/collection/TestVCCaching.java
@@ -2,7 +2,6 @@
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
@@ -15,6 +14,9 @@
 import org.apache.lucene.store.MMapDirectory;
 import org.junit.Test;
 
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
 import de.ids_mannheim.korap.Krill;
 import de.ids_mannheim.korap.KrillCollection;
 import de.ids_mannheim.korap.KrillIndex;
@@ -25,6 +27,8 @@
 
 public class TestVCCaching {
 
+    public static final ObjectMapper mapper = new ObjectMapper();
+    
     private KrillIndex getSampleIndex () throws IOException {
         return new KrillIndex(new MMapDirectory(
                 Paths.get(getClass().getResource("/sample-index").getFile())));
@@ -90,14 +94,9 @@
         String json = IOUtils.toString(is);
 
         String result = new Krill(json).apply(this.index).toJsonString();
-        assertNotNull(result);
-        assertTrue(!result.isEmpty());
-
-        // test with match:eq
-        json.replaceFirst("match:ne", "match:eq");
-        result = new Krill(json).apply(this.index).toJsonString();
-        assertNotNull(result);
-        assertTrue(!result.isEmpty());
+        System.out.println(json);
+        JsonNode node = mapper.readTree(result);
+        assertTrue(node.at("/matches").size()>0);
     }
 
     private void testClearCache () {
@@ -132,7 +131,9 @@
     }
     
     @Test
-    public void testAutoCaching () throws IOException {
+    public void testAutoCachingMatchNe () throws IOException {
+        testSearchCachedVC();
+        // search from cache
         testSearchCachedVC();
         testClearCache();
     }
diff --git a/src/test/resources/collection/query-with-vc-ref.jsonld b/src/test/resources/collection/query-with-vc-ref.jsonld
index d50cd2a..ee0bb66 100644
--- a/src/test/resources/collection/query-with-vc-ref.jsonld
+++ b/src/test/resources/collection/query-with-vc-ref.jsonld
@@ -10,6 +10,6 @@
   },
   "collection": {
     "@type": "koral:docGroupRef",
-    "ref": "cache-goe"
+    "ref": "named-vc1"
   }
 }