Fixed number of bits in DocBits.

Change-Id: I48b091887a59100fb00dbd7326b7154c28385855
diff --git a/src/main/java/de/ids_mannheim/korap/KrillCollection.java b/src/main/java/de/ids_mannheim/korap/KrillCollection.java
index a5f5008..261f080 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillCollection.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillCollection.java
@@ -300,6 +300,7 @@
             // Filter based on string
             else if (valtype.equals("type:string")) {
                 if (json.get("value").size() > 1){
+                    log.debug("koral:doc size " + json.get("value").size());
                     if (json.has("match")) {
                         match = json.get("match").asText();
                     }
@@ -829,8 +830,9 @@
         for (LeafReaderContext context : leaves) {
             if (docIdMap.get(context.hashCode()) == null) {
                 FixedBitSet bitset = bits(context);
+                DocBits docBits = new DocBits(bitset.getBits(), bitset.length());
                 docIdMap.put(context.hashCode(),
-                        new DocBits(bitset.getBits()));
+                        docBits);
             }
         }
 
diff --git a/src/main/java/de/ids_mannheim/korap/collection/CollectionBuilder.java b/src/main/java/de/ids_mannheim/korap/collection/CollectionBuilder.java
index de00b5a..feba2d1 100644
--- a/src/main/java/de/ids_mannheim/korap/collection/CollectionBuilder.java
+++ b/src/main/java/de/ids_mannheim/korap/collection/CollectionBuilder.java
@@ -1,17 +1,17 @@
 package de.ids_mannheim.korap.collection;
 
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Properties;
-import java.io.File;
-import java.io.FileInputStream;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
 import org.apache.lucene.queries.TermsFilter;
-import org.apache.lucene.search.DocIdSet;
 import org.apache.lucene.search.Filter;
 import org.apache.lucene.search.NumericRangeFilter;
 import org.apache.lucene.search.PhraseQuery;
@@ -20,15 +20,11 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import org.apache.commons.io.IOUtils;
-
 import de.ids_mannheim.korap.KrillCollection;
 import de.ids_mannheim.korap.index.TextPrependedTokenStream;
 import de.ids_mannheim.korap.util.KrillDate;
-import de.ids_mannheim.korap.util.QueryException;
-import de.ids_mannheim.korap.util.StatusCodes;
 import de.ids_mannheim.korap.util.KrillProperties;
-
+import de.ids_mannheim.korap.util.QueryException;
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.CacheManager;
 import net.sf.ehcache.Element;
diff --git a/src/main/java/de/ids_mannheim/korap/collection/DocBits.java b/src/main/java/de/ids_mannheim/korap/collection/DocBits.java
index 9b63751..f304867 100644
--- a/src/main/java/de/ids_mannheim/korap/collection/DocBits.java
+++ b/src/main/java/de/ids_mannheim/korap/collection/DocBits.java
@@ -17,13 +17,15 @@
      */
     private static final long serialVersionUID = -3505650918983180852L;
     final long[] bits;
+    final int numbits;
 
-    public DocBits (long[] bits) {
+    public DocBits (long[] bits, int numbits) {
         this.bits = bits;
+        this.numbits = numbits;
     }
 
     public BitDocIdSet createBitDocIdSet () {
-        FixedBitSet bitset = new FixedBitSet(bits, bits.length);
+        FixedBitSet bitset = new FixedBitSet(bits, numbits);
         BitDocIdSet docIdSet = new BitDocIdSet(bitset);
         return docIdSet;
     }
@@ -34,7 +36,7 @@
         int i = 1;
         for (long b : bits) {
             sb.append(b);
-            if (i < bits.length) {
+            if (i < numbits) {
                 sb.append(",");
             }
             i++;
@@ -42,4 +44,8 @@
         sb.append("]");
         return sb.toString();
     }
+    
+    public long[] getBits () {
+        return bits;
+    }
 }
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 98d911e..fe2c437 100644
--- a/src/main/java/de/ids_mannheim/korap/collection/ToCacheVCFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/collection/ToCacheVCFilter.java
@@ -59,7 +59,7 @@
             }
         }
 
-        docIdMap.put(context.hashCode(), new DocBits(bitset.getBits()));
+        docIdMap.put(context.hashCode(), new DocBits(bitset.getBits(), bitset.length()));
         CachedVCData cachedVCData = new CachedVCData(new HashMap<>(docIdMap));
 
         KrillCollection.cache.remove(cacheKey);