Lucene 5.0 update

Change-Id: I5fa86da7e959a8394652148d78248590bb71b2a7
diff --git a/Changes b/Changes
index af767f1..dbb36db 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,9 @@
+0.54 2015-10-01
+   	- [performance] Updated Lucene dependency from 4.10.3
+	  to 5.0.0 (diewald)
+        - [bugfix] Minor fixes regarding invalid tokens in the
+	  test suite (diewald)
+
 0.53 2015-09-25
         - [feature] Implemented new KrillCollection (diewald)
 	  This should fix a lot of issues with deleted
diff --git a/pom.xml b/pom.xml
index 7d1d578..e27e37d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
 
   <groupId>de.ids_mannheim.korap</groupId>
   <artifactId>Krill</artifactId>
-  <version>0.53</version>
+  <version>0.54</version>
   <packaging>jar</packaging>
 
   <name>Krill</name>
@@ -110,7 +110,7 @@
       <artifactId>lucene-core</artifactId>
       <groupId>org.apache.lucene</groupId>
       <type>jar</type>
-      <version>4.10.3</version>
+      <version>5.0.0</version>
     </dependency>
 
     <!-- Lucene queryparser dependency -->
@@ -118,7 +118,7 @@
       <artifactId>lucene-queryparser</artifactId>
       <groupId>org.apache.lucene</groupId>
       <type>jar</type>
-      <version>4.10.3</version>
+      <version>5.0.0</version>
     </dependency>
 
     <!-- Lucene analyzers dependency -->
@@ -126,7 +126,7 @@
       <artifactId>lucene-analyzers-common</artifactId>
       <groupId>org.apache.lucene</groupId>
       <type>jar</type>
-      <version>4.10.3</version>
+      <version>5.0.0</version>
     </dependency>
 
     <dependency>
diff --git a/src/main/java/de/ids_mannheim/korap/KrillCollection.java b/src/main/java/de/ids_mannheim/korap/KrillCollection.java
index d0789e3..032b817 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillCollection.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillCollection.java
@@ -13,9 +13,8 @@
 import org.apache.lucene.index.*;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.FixedBitSet;
+import org.apache.lucene.util.BitDocIdSet;
 import org.apache.lucene.util.Bits;
-import org.apache.lucene.util.OpenBitSet;
-import org.apache.lucene.util.DocIdBitSet;
 import org.apache.lucene.search.BitsFilteredDocIdSet;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -415,13 +414,13 @@
      * This will respect deleted documents.
      * 
      * @param The
-     *            {@link AtomicReaderContext} to search in.
+     *            {@link LeafReaderContext} to search in.
      * @return A bit vector representing the live documents of the
      *         virtual collection.
      * @throws IOException
      */
-    public FixedBitSet bits (AtomicReaderContext atomic) throws IOException {
-        AtomicReader r = atomic.reader();
+    public FixedBitSet bits (LeafReaderContext atomic) throws IOException {
+        LeafReader r = atomic.reader();
         FixedBitSet bitset = new FixedBitSet(r.maxDoc());
         DocIdSet docids = this.getDocIdSet(atomic, (Bits) r.getLiveDocs());
 
@@ -446,12 +445,12 @@
      * This will respect deleted documents.
      * 
      * @param atomic
-     *            The {@link AtomicReaderContext} to search in.
+     *            The {@link LeafReaderContext} to search in.
      * @param accepted
      *            {@link Bits} vector of accepted documents.
      * @throws IOException
      */
-    public DocIdSet getDocIdSet (AtomicReaderContext atomic, Bits acceptDocs)
+    public DocIdSet getDocIdSet (LeafReaderContext atomic, Bits acceptDocs)
             throws IOException {
 
         int maxDoc = atomic.reader().maxDoc();
@@ -493,7 +492,7 @@
         };
 
         // Remove deleted docs
-        return (DocIdSet) BitsFilteredDocIdSet.wrap((DocIdSet) bitset,
+        return (DocIdSet) BitsFilteredDocIdSet.wrap((DocIdSet) new BitDocIdSet(bitset),
                 acceptDocs);
     };
 
@@ -550,7 +549,7 @@
         long occurrences = 0;
         try {
             // Iterate over all atomic readers and collect occurrences
-            for (AtomicReaderContext atomic : this.index.reader().leaves()) {
+            for (LeafReaderContext atomic : this.index.reader().leaves()) {
                 Bits bits = this.bits(atomic);
 
                 if (DEBUG)
@@ -575,7 +574,7 @@
     // Search for meta information in term vectors
     // This will create the sum of all numerical payloads
     // of the term in the document vector
-    private long _numberOfAtomic (Bits docvec, AtomicReaderContext atomic,
+    private long _numberOfAtomic (Bits docvec, LeafReaderContext atomic,
             Term term) throws IOException {
 
         // This reimplements docsAndPositionsEnum with payloads
@@ -659,7 +658,7 @@
         long docCount = 0;
         try {
             FixedBitSet bitset;
-            for (AtomicReaderContext atomic : this.index.reader().leaves()) {
+            for (LeafReaderContext atomic : this.index.reader().leaves()) {
                 if ((bitset = this.bits(atomic)) != null)
                     docCount += bitset.cardinality();
             };
@@ -702,7 +701,7 @@
                 checkNumber = (long) this.reader().numDocs();
             };
 
-            for (AtomicReaderContext atomic : this.reader().leaves()) {
+            for (LeafReaderContext atomic : this.reader().leaves()) {
                 HashMap<String, FixedBitSet> termVector = new HashMap<>(20);
 
                 FixedBitSet docvec = kc.bits(atomic);
diff --git a/src/main/java/de/ids_mannheim/korap/KrillIndex.java b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
index 8a052b0..1b6fd26 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
@@ -205,7 +205,7 @@
                 new TextAnalyzer(), analyzerPerField);
 
         // Create configuration with base analyzer
-        this.config = new IndexWriterConfig(Version.LUCENE_CURRENT, analyzer);
+        this.config = new IndexWriterConfig(analyzer);
     };
 
 
@@ -612,7 +612,7 @@
             long docCount = 0;
             // int i = 1;
             try {
-                for (AtomicReaderContext atomic : this.reader().leaves()) {
+                for (LeafReaderContext atomic : this.reader().leaves()) {
                     docCount += collection.bits(atomic).cardinality();
                     // i++;
                 };
@@ -630,7 +630,7 @@
         long occurrences = 0;
         try {
             // Iterate over all atomic readers and collect occurrences
-            for (AtomicReaderContext atomic : this.reader().leaves()) {
+            for (LeafReaderContext atomic : this.reader().leaves()) {
                 occurrences += this._numberOfAtomic(collection.bits(atomic),
                         atomic, term);
             };
@@ -699,12 +699,13 @@
      * @return The number of the occurrences.
      * @throws IOException
      */
+        /*
     @Deprecated
     public long numberOf (Bits docvec, String field, String type)
             throws IOException {
         // Shortcut for documents
         if (type.equals("documents")) {
-            OpenBitSet os = (OpenBitSet) docvec;
+            FixedBitSet os = (FixedBitSet) docvec;
             return os.cardinality();
         };
 
@@ -712,7 +713,7 @@
 
         int occurrences = 0;
         try {
-            for (AtomicReaderContext atomic : this.reader().leaves()) {
+            for (LeafReaderContext atomic : this.reader().leaves()) {
                 occurrences += this._numberOfAtomic(docvec, atomic, term);
             };
         }
@@ -722,14 +723,14 @@
 
         return occurrences;
     };
-
+*/
 
 
     // Search for meta information in term vectors
     // This will create the sum of all numerical payloads
     // of the term in the document vector
     @Deprecated
-    private long _numberOfAtomic (Bits docvec, AtomicReaderContext atomic,
+    private long _numberOfAtomic (Bits docvec, LeafReaderContext atomic,
             Term term) throws IOException {
 
         // This reimplements docsAndPositionsEnum with payloads
@@ -962,7 +963,7 @@
 
         try {
             // Iterate over all atomic indices and find the matching document
-            for (AtomicReaderContext atomic : this.reader().leaves()) {
+            for (LeafReaderContext atomic : this.reader().leaves()) {
 
                 // Retrieve the single document of interest
                 DocIdSet filterSet = filter.getDocIdSet(atomic, atomic.reader()
@@ -1263,13 +1264,13 @@
 
 
             // Todo: run this in a separated thread
-            for (AtomicReaderContext atomic : this.reader().leaves()) {
+            for (LeafReaderContext atomic : this.reader().leaves()) {
 
                 int oldLocalDocID = -1;
 
                 /*
                  * Todo: There may be a way to know early if the bitset is emty
-                 * by using OpenBitSet - but this may not be as fast as I think.
+                 * by using LongBitSet - but this may not be as fast as I think.
                  */
                 final Bits bitset = collection.bits(atomic);
                 final PositionsToOffset pto = new PositionsToOffset(atomic,
@@ -1486,12 +1487,12 @@
             int uniqueDocID = -1;
 
             // start thread:
-            for (AtomicReaderContext atomic : this.reader().leaves()) {
+            for (LeafReaderContext atomic : this.reader().leaves()) {
 
                 int previousDocID = -1;
                 int oldLocalDocID = -1;
 
-                // Use OpenBitSet;
+                // Use LongBitSet;
                 Bits bitset = collection.bits(atomic);
 
                 // PositionsToOffset pto = new PositionsToOffset(atomic, field);
diff --git a/src/main/java/de/ids_mannheim/korap/collection/BooleanGroupFilter.java b/src/main/java/de/ids_mannheim/korap/collection/BooleanGroupFilter.java
index 53b0b66..1e5c878 100644
--- a/src/main/java/de/ids_mannheim/korap/collection/BooleanGroupFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/collection/BooleanGroupFilter.java
@@ -8,9 +8,10 @@
 import org.apache.lucene.search.DocIdSet;
 import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.search.BitsFilteredDocIdSet;
-import org.apache.lucene.index.AtomicReaderContext;
-import org.apache.lucene.index.AtomicReader;
+import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.LeafReader;
 import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.BitDocIdSet;
 
 import de.ids_mannheim.korap.KrillCollection;
 
@@ -120,11 +121,18 @@
         return buffer.append(')').toString();
     };
 
+    /*
+    @Override
+    public String toString (String str) {
+        return this.toString();
+    };
+    */
+
 
     @Override
-    public DocIdSet getDocIdSet (AtomicReaderContext context, Bits acceptDocs)
+    public DocIdSet getDocIdSet (LeafReaderContext context, Bits acceptDocs)
             throws IOException {
-        final AtomicReader reader = context.reader();
+        final LeafReader reader = context.reader();
         int maxDoc = reader.maxDoc();
         FixedBitSet bitset = new FixedBitSet(maxDoc);
         FixedBitSet combinator = new FixedBitSet(maxDoc);
@@ -159,7 +167,7 @@
                             log.debug("- Filter to allow all documents");
 
                         bitset.set(0, maxDoc);
-                        return BitsFilteredDocIdSet.wrap(bitset, acceptDocs);
+                        return BitsFilteredDocIdSet.wrap(new BitDocIdSet(bitset), acceptDocs);
                     };
 
                     // There is no possible match
@@ -250,6 +258,6 @@
                     log.debug("- Subresult has card {} ", bitset.cardinality());
             };
         };
-        return BitsFilteredDocIdSet.wrap(bitset, acceptDocs);
+        return BitsFilteredDocIdSet.wrap(new BitDocIdSet(bitset), acceptDocs);
     };
 };
diff --git a/src/main/java/de/ids_mannheim/korap/index/FieldDocument.java b/src/main/java/de/ids_mannheim/korap/index/FieldDocument.java
index f1a4e12..a0c1994 100644
--- a/src/main/java/de/ids_mannheim/korap/index/FieldDocument.java
+++ b/src/main/java/de/ids_mannheim/korap/index/FieldDocument.java
@@ -18,7 +18,7 @@
 import org.apache.lucene.document.IntField;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.FieldType;
-import org.apache.lucene.index.FieldInfo.IndexOptions;
+import org.apache.lucene.index.IndexOptions;
 
 import java.util.*;
 
@@ -60,7 +60,7 @@
         keywords.setStoreTermVectorPositions(false);
         keywords.setStoreTermVectorPayloads(false);
         keywords.setStoreTermVectorOffsets(false);
-        keywords.setIndexOptions(IndexOptions.DOCS_ONLY);
+        keywords.setIndexOptions(IndexOptions.DOCS);
     };
 
 
diff --git a/src/main/java/de/ids_mannheim/korap/index/Indexer.java b/src/main/java/de/ids_mannheim/korap/index/Indexer.java
index 1cc5221..33e5eb2 100644
--- a/src/main/java/de/ids_mannheim/korap/index/Indexer.java
+++ b/src/main/java/de/ids_mannheim/korap/index/Indexer.java
@@ -7,6 +7,7 @@
 import static de.ids_mannheim.korap.util.KrillProperties.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import java.nio.file.Paths;
 
 /**
  * Standalone indexer tool for Krill.
@@ -48,7 +49,7 @@
                 "1000");
 
         // Create a new index object based on the directory
-        this.index = new KrillIndex(new MMapDirectory(new File(this.path)));
+        this.index = new KrillIndex(new MMapDirectory(Paths.get(this.path)));
         this.count = 0;
         this.commitCount = Integer.parseInt(commitCount);
     };
diff --git a/src/main/java/de/ids_mannheim/korap/index/KeywordAnalyzer.java b/src/main/java/de/ids_mannheim/korap/index/KeywordAnalyzer.java
index 0725778..e16abae 100644
--- a/src/main/java/de/ids_mannheim/korap/index/KeywordAnalyzer.java
+++ b/src/main/java/de/ids_mannheim/korap/index/KeywordAnalyzer.java
@@ -11,9 +11,8 @@
 public class KeywordAnalyzer extends Analyzer {
 
     @Override
-    protected TokenStreamComponents createComponents (final String fieldName,
-            final Reader reader) {
-        final Tokenizer source = new WhitespaceTokenizer(reader);
+    protected TokenStreamComponents createComponents (final String fieldName) {
+        final Tokenizer source = new WhitespaceTokenizer();
         TokenStream sink = new LowerCaseFilter(source);
         return new TokenStreamComponents(source, sink);
     };
diff --git a/src/main/java/de/ids_mannheim/korap/index/MultiTermTokenStream.java b/src/main/java/de/ids_mannheim/korap/index/MultiTermTokenStream.java
index de974c3..4b363dd 100644
--- a/src/main/java/de/ids_mannheim/korap/index/MultiTermTokenStream.java
+++ b/src/main/java/de/ids_mannheim/korap/index/MultiTermTokenStream.java
@@ -3,6 +3,7 @@
 import static de.ids_mannheim.korap.util.KrillByte.*;
 import de.ids_mannheim.korap.util.CorpusDataException;
 import org.apache.lucene.util.BytesRef;
+import java.nio.ByteBuffer;
 
 import java.util.*;
 import java.util.regex.*;
@@ -47,7 +48,7 @@
             .compile("\\[(?:\\([0-9]+-[0-9]+\\))?([^\\]]+?)\\]");
 
     // This advices the java compiler to ignore all loggings
-    public static final boolean DEBUG = false;
+    public static final boolean DEBUG = true;
     private final Logger log = LoggerFactory
             .getLogger(MultiTermTokenStream.class);
 
@@ -55,6 +56,8 @@
     private int mttIndex = 0, mtIndex = 0;
     private short i = 0;
 
+    private ByteBuffer payload = ByteBuffer.allocate(36);
+
 
     /**
      * Construct a new MultiTermTokenStream object.
@@ -398,7 +401,7 @@
         charTermAttr.setEmpty();
         charTermAttr.append(mt.term);
 
-        BytesRef payload = new BytesRef();
+        payload.rewind();
 
         // There is offset information
         if (mt.start != mt.end) {
@@ -407,20 +410,41 @@
                         mt.end);
 
             // Add offsets to BytesRef payload
-            payload.append(new BytesRef(int2byte(mt.start)));
-            payload.append(new BytesRef(int2byte(mt.end)));
+            payload.putInt(mt.start);
+            payload.putInt(mt.end);
         };
 
         // There is payload in the MultiTerm
         if (mt.payload != null) {
-            payload.append(mt.payload);
+            
+            payload.put(mt.payload.bytes);
+
+            if (payload.position() > 18) {
+                System.err.println(mt.toString() + " has " + payload.toString());
+            };
+
             if (DEBUG)
                 log.trace("Create payload[1] {}", payload.toString());
         };
 
         // There is payload in the current token to index
-        if (payload.length > 0) {
-            payloadAttr.setPayload(payload);
+        // This seems to be heavily risky!
+        if (payload.position() > 0) {
+
+            if (payload.hasArray()) {
+                payloadAttr.setPayload(
+                                       new BytesRef(
+                                                    Arrays.copyOfRange(payload.array(),
+                                                                       payload.arrayOffset(),
+                                                                       payload.arrayOffset() + payload.position()
+                                                                       )
+                                                    )
+                                       );
+            }
+            else {
+                log.error("This should never happen!");
+            };
+
             if (DEBUG)
                 log.trace("Set payload[2] {}", payload.toString());
         };
@@ -429,7 +453,7 @@
         if (DEBUG) {
             StringBuilder sb = new StringBuilder("Index: [");
             sb.append(mt.term);
-            if (payload.length > 0)
+            if (payload.position() > 0)
                 sb.append('$').append(payload.toString());
             sb.append(']');
             sb.append(" with increment ").append(this.mtIndex == 0 ? 1 : 0);
diff --git a/src/main/java/de/ids_mannheim/korap/index/PositionsToOffset.java b/src/main/java/de/ids_mannheim/korap/index/PositionsToOffset.java
index 0440286..bd84972 100644
--- a/src/main/java/de/ids_mannheim/korap/index/PositionsToOffset.java
+++ b/src/main/java/de/ids_mannheim/korap/index/PositionsToOffset.java
@@ -6,7 +6,7 @@
 import java.nio.ByteBuffer;
 
 import org.apache.lucene.index.DocsAndPositionsEnum;
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Terms;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermsEnum;
@@ -17,7 +17,7 @@
 
 public class PositionsToOffset {
     private String field;
-    private AtomicReaderContext atomic;
+    private LeafReaderContext atomic;
     private boolean processed = false;
     private Integer[] pair;
     private static ByteBuffer bbOffset = ByteBuffer.allocate(8);
@@ -59,7 +59,7 @@
     };
 
 
-    public PositionsToOffset (AtomicReaderContext atomic, String field) {
+    public PositionsToOffset (LeafReaderContext atomic, String field) {
         this.field = field;
         this.atomic = atomic;
         this.positions = new HashSet<>(64);
@@ -252,7 +252,7 @@
     };
 
 
-    public AtomicReaderContext getAtomicReader () {
+    public LeafReaderContext getLeafReader () {
         return this.atomic;
     };
 };
diff --git a/src/main/java/de/ids_mannheim/korap/index/TextAnalyzer.java b/src/main/java/de/ids_mannheim/korap/index/TextAnalyzer.java
index 771c6c1..205b201 100644
--- a/src/main/java/de/ids_mannheim/korap/index/TextAnalyzer.java
+++ b/src/main/java/de/ids_mannheim/korap/index/TextAnalyzer.java
@@ -11,9 +11,8 @@
 public class TextAnalyzer extends Analyzer {
 
     @Override
-    protected TokenStreamComponents createComponents (final String fieldName,
-            final Reader reader) {
-        final Tokenizer source = new StandardTokenizer(reader);
+    protected TokenStreamComponents createComponents (final String fieldName) {
+        final Tokenizer source = new StandardTokenizer();
         TokenStream sink = new LowerCaseFilter(source);
         return new TokenStreamComponents(source, sink);
     };
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanAttributeQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanAttributeQuery.java
index a4194b1..265d2de 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanAttributeQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanAttributeQuery.java
@@ -3,7 +3,7 @@
 import java.io.IOException;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.SpanQuery;
@@ -109,7 +109,7 @@
 
 
     @Override
-    public Spans getSpans (AtomicReaderContext context, Bits acceptDocs,
+    public Spans getSpans (LeafReaderContext context, Bits acceptDocs,
             Map<Term, TermContext> termContexts) throws IOException {
         return new AttributeSpans(this, context, acceptDocs, termContexts);
     }
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanClassFilterQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanClassFilterQuery.java
index 799c87e..b5a8653 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanClassFilterQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanClassFilterQuery.java
@@ -3,7 +3,7 @@
 import java.io.IOException;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.SpanQuery;
@@ -40,7 +40,7 @@
 
 
     @Override
-    public Spans getSpans (AtomicReaderContext context, Bits acceptDocs,
+    public Spans getSpans (LeafReaderContext context, Bits acceptDocs,
             Map<Term, TermContext> termContexts) throws IOException {
         return new ClassFilteredSpans(this, context, acceptDocs, termContexts);
     }
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanClassQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanClassQuery.java
index 8de7faf..0b2df96 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanClassQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanClassQuery.java
@@ -3,7 +3,7 @@
 import java.io.IOException;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
@@ -45,7 +45,7 @@
 
 
     @Override
-    public Spans getSpans (final AtomicReaderContext context, Bits acceptDocs,
+    public Spans getSpans (final LeafReaderContext context, Bits acceptDocs,
             Map<Term, TermContext> termContexts) throws IOException {
         return (Spans) new ClassSpans(this.firstClause, context, acceptDocs,
                 termContexts, number);
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanDistanceQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanDistanceQuery.java
index c77bf71..da53af7 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanDistanceQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanDistanceQuery.java
@@ -3,7 +3,7 @@
 import java.io.IOException;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.SpanQuery;
@@ -205,7 +205,7 @@
 
 
     @Override
-    public Spans getSpans (AtomicReaderContext context, Bits acceptDocs,
+    public Spans getSpans (LeafReaderContext context, Bits acceptDocs,
             Map<Term, TermContext> termContexts) throws IOException {
 
         if (this.elementQuery != null) {
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanElementQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanElementQuery.java
index 937e9bc..bf7d51f 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanElementQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanElementQuery.java
@@ -4,7 +4,7 @@
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.SpanTermQuery;
@@ -69,7 +69,7 @@
 
 
     @Override
-    public Spans getSpans (final AtomicReaderContext context, Bits acceptDocs,
+    public Spans getSpans (final LeafReaderContext context, Bits acceptDocs,
             Map<Term, TermContext> termContexts) throws IOException {
         return new ElementSpans(this, context, acceptDocs, termContexts);
     };
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanExpansionQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanExpansionQuery.java
index 2fb8e84..d7130e1 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanExpansionQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanExpansionQuery.java
@@ -3,7 +3,7 @@
 import java.io.IOException;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.SpanQuery;
@@ -265,7 +265,7 @@
 
 
     @Override
-    public Spans getSpans (AtomicReaderContext context, Bits acceptDocs,
+    public Spans getSpans (LeafReaderContext context, Bits acceptDocs,
             Map<Term, TermContext> termContexts) throws IOException {
 
         //	      Temporary:
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanFocusQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanFocusQuery.java
index ab29d0f..ace6183 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanFocusQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanFocusQuery.java
@@ -5,7 +5,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
@@ -105,7 +105,7 @@
 
 
     @Override
-    public Spans getSpans (final AtomicReaderContext context, Bits acceptDocs,
+    public Spans getSpans (final LeafReaderContext context, Bits acceptDocs,
             Map<Term, TermContext> termContexts) throws IOException {
         return new FocusSpans(this, context, acceptDocs, termContexts);
     };
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanMultipleDistanceQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanMultipleDistanceQuery.java
index b8553d9..51ba29b 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanMultipleDistanceQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanMultipleDistanceQuery.java
@@ -4,7 +4,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.SpanQuery;
@@ -167,7 +167,7 @@
      * @return only the span matches meeting all the constraints.
      * */
     @Override
-    public Spans getSpans (AtomicReaderContext context, Bits acceptDocs,
+    public Spans getSpans (LeafReaderContext context, Bits acceptDocs,
             Map<Term, TermContext> termContexts) throws IOException {
 
         SpanDistanceQuery sdq, sdq2;
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanNextQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanNextQuery.java
index 6a0c679..fb0d382 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanNextQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanNextQuery.java
@@ -3,7 +3,7 @@
 import java.io.IOException;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
@@ -88,7 +88,8 @@
 
 
     @Override
-    public Spans getSpans (final AtomicReaderContext context, Bits acceptDocs,
+    // TODO: 5.3 removes getSpans fro SpanQuery ... oh, well ...
+    public Spans getSpans (final LeafReaderContext context, Bits acceptDocs,
             Map<Term, TermContext> termContexts) throws IOException {
         return (Spans) new NextSpans(this, context, acceptDocs, termContexts);
     };
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanReferenceQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanReferenceQuery.java
index 3b23a18..241b6ce 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanReferenceQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanReferenceQuery.java
@@ -3,7 +3,7 @@
 import java.io.IOException;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.SpanQuery;
@@ -32,7 +32,7 @@
 
 
     @Override
-    public Spans getSpans (AtomicReaderContext context, Bits acceptDocs,
+    public Spans getSpans (LeafReaderContext context, Bits acceptDocs,
             Map<Term, TermContext> termContexts) throws IOException {
         // TODO Auto-generated method stub
         return new ReferenceSpans(this, context, acceptDocs, termContexts);
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanRelationMatchQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanRelationMatchQuery.java
index 0fac2a3..e0b8dd6 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanRelationMatchQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanRelationMatchQuery.java
@@ -3,7 +3,7 @@
 import java.io.IOException;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.SpanQuery;
@@ -119,7 +119,7 @@
 
 
     @Override
-    public Spans getSpans (AtomicReaderContext context, Bits acceptDocs,
+    public Spans getSpans (LeafReaderContext context, Bits acceptDocs,
             Map<Term, TermContext> termContexts) throws IOException {
 
         return new FocusSpans((SpanFocusQuery) firstClause, context,
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanRelationQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanRelationQuery.java
index 65b8786..d62216b 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanRelationQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanRelationQuery.java
@@ -5,7 +5,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.SpanQuery;
@@ -105,7 +105,7 @@
 
 
     @Override
-    public Spans getSpans (AtomicReaderContext context, Bits acceptDocs,
+    public Spans getSpans (LeafReaderContext context, Bits acceptDocs,
             Map<Term, TermContext> termContexts) throws IOException {
         return new RelationSpans(this, context, acceptDocs, termContexts);
     }
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanRepetitionQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanRepetitionQuery.java
index 7e95bf6..92c6c94 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanRepetitionQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanRepetitionQuery.java
@@ -3,7 +3,7 @@
 import java.io.IOException;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.SpanQuery;
@@ -88,7 +88,7 @@
 
 
     @Override
-    public Spans getSpans (AtomicReaderContext context, Bits acceptDocs,
+    public Spans getSpans (LeafReaderContext context, Bits acceptDocs,
             Map<Term, TermContext> termContexts) throws IOException {
         return new RepetitionSpans(this, context, acceptDocs, termContexts);
     }
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanSegmentQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanSegmentQuery.java
index 29189e2..508c7ca 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanSegmentQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanSegmentQuery.java
@@ -3,7 +3,7 @@
 import java.io.IOException;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.SpanQuery;
@@ -70,7 +70,7 @@
 
 
     @Override
-    public Spans getSpans (AtomicReaderContext context, Bits acceptDocs,
+    public Spans getSpans (LeafReaderContext context, Bits acceptDocs,
             Map<Term, TermContext> termContexts) throws IOException {
         return (Spans) new SegmentSpans(this, context, acceptDocs, termContexts);
     }
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanSubspanQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanSubspanQuery.java
index 010d077..84f589d 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanSubspanQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanSubspanQuery.java
@@ -3,7 +3,7 @@
 import java.io.IOException;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.SpanQuery;
@@ -79,7 +79,7 @@
 
 
     @Override
-    public Spans getSpans (AtomicReaderContext context, Bits acceptDocs,
+    public Spans getSpans (LeafReaderContext context, Bits acceptDocs,
             Map<Term, TermContext> termContexts) throws IOException {
         return new SubSpans(this, context, acceptDocs, termContexts);
     }
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanTermWithIdQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanTermWithIdQuery.java
index 87de370..324d560 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanTermWithIdQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanTermWithIdQuery.java
@@ -3,7 +3,7 @@
 import java.io.IOException;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.SpanTermQuery;
@@ -57,7 +57,7 @@
 
 
     @Override
-    public Spans getSpans (AtomicReaderContext context, Bits acceptDocs,
+    public Spans getSpans (LeafReaderContext context, Bits acceptDocs,
             Map<Term, TermContext> termContexts) throws IOException {
         return new TermSpansWithId(this, context, acceptDocs, termContexts);
     }
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanWithAttributeQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanWithAttributeQuery.java
index 2ea519a..ce08c62 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanWithAttributeQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanWithAttributeQuery.java
@@ -5,7 +5,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.SpanQuery;
@@ -185,7 +185,7 @@
 
 
     @Override
-    public Spans getSpans (AtomicReaderContext context, Bits acceptDocs,
+    public Spans getSpans (LeafReaderContext context, Bits acceptDocs,
             Map<Term, TermContext> termContexts) throws IOException {
 
         if (type.equals("spanWithAttribute")) {
diff --git a/src/main/java/de/ids_mannheim/korap/query/SpanWithinQuery.java b/src/main/java/de/ids_mannheim/korap/query/SpanWithinQuery.java
index ee79869..e658046 100644
--- a/src/main/java/de/ids_mannheim/korap/query/SpanWithinQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/SpanWithinQuery.java
@@ -9,11 +9,11 @@
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.spans.SpanQuery;
 import org.apache.lucene.search.spans.Spans;
@@ -160,7 +160,7 @@
 
 
     @Override
-    public Spans getSpans (final AtomicReaderContext context, Bits acceptDocs,
+    public Spans getSpans (final LeafReaderContext context, Bits acceptDocs,
             Map<Term, TermContext> termContexts) throws IOException {
         return (Spans) new WithinSpans(this, context, acceptDocs, termContexts,
                 this.flag);
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/AttributeSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/AttributeSpans.java
index cf70cb9..91b85bf 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/AttributeSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/AttributeSpans.java
@@ -7,7 +7,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.Spans;
@@ -65,7 +65,7 @@
      * @throws IOException
      */
     public AttributeSpans (SpanAttributeQuery spanAttributeQuery,
-                           AtomicReaderContext context, Bits acceptDocs,
+                           LeafReaderContext context, Bits acceptDocs,
                            Map<Term, TermContext> termContexts)
             throws IOException {
         super(spanAttributeQuery, context, acceptDocs, termContexts);
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/ClassFilteredSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/ClassFilteredSpans.java
index 28459cf..57d3d81 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/ClassFilteredSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/ClassFilteredSpans.java
@@ -6,7 +6,7 @@
 import java.util.BitSet;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.util.Bits;
@@ -22,7 +22,7 @@
 
 
     public ClassFilteredSpans (SpanClassFilterQuery query,
-                               AtomicReaderContext context, Bits acceptDocs,
+                               LeafReaderContext context, Bits acceptDocs,
                                Map<Term, TermContext> termContexts)
             throws IOException {
         super(query, context, acceptDocs, termContexts);
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/ClassSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/ClassSpans.java
index 09cc05b..37036b4 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/ClassSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/ClassSpans.java
@@ -7,7 +7,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.index.TermState;
@@ -47,7 +47,7 @@
      * @param operand
      *            An arbitrary nested {@link SpanQuery}.
      * @param context
-     *            The {@link AtomicReaderContext}.
+     *            The {@link LeafReaderContext}.
      * @param acceptDocs
      *            Bit vector representing the documents
      *            to be searched in.
@@ -56,7 +56,7 @@
      * @param number
      *            The identifying class number.
      */
-    public ClassSpans (SpanQuery operand, AtomicReaderContext context,
+    public ClassSpans (SpanQuery operand, LeafReaderContext context,
                        Bits acceptDocs, Map<Term, TermContext> termContexts,
                        byte number) throws IOException {
         spans = operand.getSpans(context, acceptDocs, termContexts);
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/DistanceExclusionSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/DistanceExclusionSpans.java
index 517e8f8..d3b9f6f 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/DistanceExclusionSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/DistanceExclusionSpans.java
@@ -3,7 +3,7 @@
 import java.io.IOException;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.util.Bits;
@@ -42,7 +42,7 @@
      * @throws IOException
      */
     public DistanceExclusionSpans (SpanDistanceQuery query,
-                                   AtomicReaderContext context,
+                                   LeafReaderContext context,
                                    Bits acceptDocs,
                                    Map<Term, TermContext> termContexts)
             throws IOException {
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/DistanceSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/DistanceSpans.java
index b6b6f9f..7bc9136 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/DistanceSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/DistanceSpans.java
@@ -3,7 +3,7 @@
 import java.io.IOException;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.util.Bits;
@@ -48,7 +48,7 @@
      * @param termContexts
      * @throws IOException
      */
-    public DistanceSpans (SpanDistanceQuery query, AtomicReaderContext context,
+    public DistanceSpans (SpanDistanceQuery query, LeafReaderContext context,
                           Bits acceptDocs, Map<Term, TermContext> termContexts)
             throws IOException {
         super(query, context, acceptDocs, termContexts);
@@ -68,7 +68,7 @@
      * @throws IOException
      */
     public DistanceSpans (SpanMultipleDistanceQuery query,
-                          AtomicReaderContext context, Bits acceptDocs,
+                          LeafReaderContext context, Bits acceptDocs,
                           Map<Term, TermContext> termContexts)
             throws IOException {
         super(query, context, acceptDocs, termContexts);
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/ElementDistanceExclusionSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/ElementDistanceExclusionSpans.java
index f5fc8cb..78c0e76 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/ElementDistanceExclusionSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/ElementDistanceExclusionSpans.java
@@ -6,7 +6,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.Spans;
@@ -63,7 +63,7 @@
      * @throws IOException
      */
     public ElementDistanceExclusionSpans (SpanDistanceQuery query,
-                                          AtomicReaderContext context,
+                                          LeafReaderContext context,
                                           Bits acceptDocs,
                                           Map<Term, TermContext> termContexts)
             throws IOException {
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/ElementDistanceSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/ElementDistanceSpans.java
index ac8fe24..5f3ded5 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/ElementDistanceSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/ElementDistanceSpans.java
@@ -4,7 +4,7 @@
 import java.util.Iterator;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.Spans;
@@ -45,7 +45,7 @@
      * @throws IOException
      */
     public ElementDistanceSpans (SpanDistanceQuery query,
-                                 AtomicReaderContext context, Bits acceptDocs,
+                                 LeafReaderContext context, Bits acceptDocs,
                                  Map<Term, TermContext> termContexts)
             throws IOException {
         super(query, context, acceptDocs, termContexts);
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/ElementSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/ElementSpans.java
index 0e4768d..9616ba3 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/ElementSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/ElementSpans.java
@@ -8,7 +8,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.index.TermState;
@@ -44,7 +44,7 @@
      * @param spanElementQuery
      *            A {@link SpanElementQuery}.
      * @param context
-     *            The {@link AtomicReaderContext}.
+     *            The {@link LeafReaderContext}.
      * @param acceptDocs
      *            Bit vector representing the documents
      *            to be searched in.
@@ -53,7 +53,7 @@
      * @throws IOException
      */
     public ElementSpans (SpanElementQuery spanElementQuery,
-                         AtomicReaderContext context, Bits acceptDocs,
+                         LeafReaderContext context, Bits acceptDocs,
                          Map<Term, TermContext> termContexts)
             throws IOException {
         super(spanElementQuery, context, acceptDocs, termContexts);
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/ExpandedExclusionSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/ExpandedExclusionSpans.java
index 19f7e7f..6b6fee0 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/ExpandedExclusionSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/ExpandedExclusionSpans.java
@@ -6,7 +6,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.Spans;
@@ -62,7 +62,7 @@
      * @throws IOException
      */
     public ExpandedExclusionSpans (SpanExpansionQuery spanExpansionQuery,
-                                   AtomicReaderContext context,
+                                   LeafReaderContext context,
                                    Bits acceptDocs,
                                    Map<Term, TermContext> termContexts)
             throws IOException {
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/ExpandedSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/ExpandedSpans.java
index b378d43..29e8900 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/ExpandedSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/ExpandedSpans.java
@@ -6,7 +6,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.util.Bits;
@@ -49,7 +49,7 @@
      * @throws IOException
      */
     public ExpandedSpans (SpanExpansionQuery spanExpansionQuery,
-                          AtomicReaderContext context, Bits acceptDocs,
+                          LeafReaderContext context, Bits acceptDocs,
                           Map<Term, TermContext> termContexts)
             throws IOException {
         super(spanExpansionQuery, context, acceptDocs, termContexts);
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/FocusSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/FocusSpans.java
index 9598ac0..10d740c 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/FocusSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/FocusSpans.java
@@ -8,7 +8,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.index.TermState;
@@ -64,7 +64,7 @@
      * @param query
      *            A {@link SpanQuery}.
      * @param context
-     *            The {@link AtomicReaderContext}.
+     *            The {@link LeafReaderContext}.
      * @param acceptDocs
      *            Bit vector representing the documents
      *            to be searched in.
@@ -74,7 +74,7 @@
      *            The class number to focus on.
      * @throws IOException
      */
-    public FocusSpans (SpanFocusQuery query, AtomicReaderContext context,
+    public FocusSpans (SpanFocusQuery query, LeafReaderContext context,
                        Bits acceptDocs, Map<Term, TermContext> termContexts)
             throws IOException {
         super(query, context, acceptDocs, termContexts);
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/MultipleDistanceSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/MultipleDistanceSpans.java
index 63d355f..f1b7973 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/MultipleDistanceSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/MultipleDistanceSpans.java
@@ -3,7 +3,7 @@
 import java.io.IOException;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.Spans;
@@ -61,7 +61,7 @@
      * @throws IOException
      */
     public MultipleDistanceSpans (SpanMultipleDistanceQuery query,
-                                  AtomicReaderContext context, Bits acceptDocs,
+                                  LeafReaderContext context, Bits acceptDocs,
                                   Map<Term, TermContext> termContexts,
                                   Spans firstSpans, Spans secondSpans,
                                   boolean isOrdered, boolean exclusion)
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/NextSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/NextSpans.java
index 9c8fa28..34045fb 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/NextSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/NextSpans.java
@@ -6,7 +6,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.util.Bits;
@@ -46,7 +46,7 @@
      * @param termContexts
      * @throws IOException
      */
-    public NextSpans (SpanNextQuery spanNextQuery, AtomicReaderContext context,
+    public NextSpans (SpanNextQuery spanNextQuery, LeafReaderContext context,
                       Bits acceptDocs, Map<Term, TermContext> termContexts)
             throws IOException {
         super(spanNextQuery, context, acceptDocs, termContexts);
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/NonPartialOverlappingSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/NonPartialOverlappingSpans.java
index d7f41da..07d1526 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/NonPartialOverlappingSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/NonPartialOverlappingSpans.java
@@ -4,7 +4,7 @@
 import java.util.Collection;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.util.Bits;
@@ -38,7 +38,7 @@
      * @throws IOException
      */
     public NonPartialOverlappingSpans (SimpleSpanQuery simpleSpanQuery,
-                                       AtomicReaderContext context,
+                                       LeafReaderContext context,
                                        Bits acceptDocs,
                                        Map<Term, TermContext> termContexts)
             throws IOException {
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/OrderedDistanceSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/OrderedDistanceSpans.java
index 88d5bc3..64507ab 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/OrderedDistanceSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/OrderedDistanceSpans.java
@@ -5,7 +5,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.util.Bits;
@@ -39,7 +39,7 @@
      * @throws IOException
      */
     public OrderedDistanceSpans (SpanDistanceQuery query,
-                                 AtomicReaderContext context, Bits acceptDocs,
+                                 LeafReaderContext context, Bits acceptDocs,
                                  Map<Term, TermContext> termContexts)
             throws IOException {
         super(query, context, acceptDocs, termContexts);
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/ReferenceSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/ReferenceSpans.java
index cae4c5a..7d855e0 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/ReferenceSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/ReferenceSpans.java
@@ -5,7 +5,7 @@
 import java.io.IOException;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.util.Bits;
@@ -18,7 +18,7 @@
 
 
     public ReferenceSpans (SpanReferenceQuery query,
-                           AtomicReaderContext context, Bits acceptDocs,
+                           LeafReaderContext context, Bits acceptDocs,
                            Map<Term, TermContext> termContexts)
             throws IOException {
         super(query, context, acceptDocs, termContexts);
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/RelationBaseSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/RelationBaseSpans.java
index d8299ef..b00dc43 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/RelationBaseSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/RelationBaseSpans.java
@@ -3,7 +3,7 @@
 import java.io.IOException;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.util.Bits;
@@ -50,7 +50,7 @@
      * @throws IOException
      */
     public RelationBaseSpans (SimpleSpanQuery spanWithIdQuery,
-                              AtomicReaderContext context, Bits acceptDocs,
+                              LeafReaderContext context, Bits acceptDocs,
                               Map<Term, TermContext> termContexts)
             throws IOException {
         super(spanWithIdQuery, context, acceptDocs, termContexts);
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/RelationSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/RelationSpans.java
index 979b359..fcc8645 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/RelationSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/RelationSpans.java
@@ -7,7 +7,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.Spans;
@@ -74,7 +74,7 @@
      * @throws IOException
      */
     public RelationSpans (SpanRelationQuery relationSpanQuery,
-                          AtomicReaderContext context, Bits acceptDocs,
+                          LeafReaderContext context, Bits acceptDocs,
                           Map<Term, TermContext> termContexts)
             throws IOException {
         super(relationSpanQuery, context, acceptDocs, termContexts);
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/RepetitionSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/RepetitionSpans.java
index 1809309..6764c9d 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/RepetitionSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/RepetitionSpans.java
@@ -7,7 +7,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.util.Bits;
@@ -40,7 +40,7 @@
      * @throws IOException
      */
     public RepetitionSpans (SpanRepetitionQuery query,
-                            AtomicReaderContext context, Bits acceptDocs,
+                            LeafReaderContext context, Bits acceptDocs,
                             Map<Term, TermContext> termContexts)
             throws IOException {
         super(query, context, acceptDocs, termContexts);
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/SegmentSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/SegmentSpans.java
index 9d40d31..46e4b28 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/SegmentSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/SegmentSpans.java
@@ -4,7 +4,7 @@
 import java.util.Collection;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.util.Bits;
@@ -34,7 +34,7 @@
      * @throws IOException
      */
     public SegmentSpans (SpanSegmentQuery spanSegmentQuery,
-                         AtomicReaderContext context, Bits acceptDocs,
+                         LeafReaderContext context, Bits acceptDocs,
                          Map<Term, TermContext> termContexts)
             throws IOException {
         super(spanSegmentQuery, context, acceptDocs, termContexts);
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/SimpleSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/SimpleSpans.java
index d82b8fa..76a1cec 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/SimpleSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/SimpleSpans.java
@@ -5,7 +5,7 @@
 import java.util.Collection;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.SpanQuery;
@@ -48,7 +48,7 @@
 
 
     public SimpleSpans (SimpleSpanQuery simpleSpanQuery,
-                        AtomicReaderContext context, Bits acceptDocs,
+                        LeafReaderContext context, Bits acceptDocs,
                         Map<Term, TermContext> termContexts) throws IOException {
         this();
         query = simpleSpanQuery;
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/SpansWithAttribute.java b/src/main/java/de/ids_mannheim/korap/query/spans/SpansWithAttribute.java
index 8f0e0b9..c38b332 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/SpansWithAttribute.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/SpansWithAttribute.java
@@ -5,7 +5,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.SpanQuery;
@@ -57,7 +57,7 @@
      */
     public SpansWithAttribute (SpanWithAttributeQuery spanWithAttributeQuery,
                                SimpleSpans referentSpans,
-                               AtomicReaderContext context, Bits acceptDocs,
+                               LeafReaderContext context, Bits acceptDocs,
                                Map<Term, TermContext> termContexts)
             throws IOException {
         super(spanWithAttributeQuery, context, acceptDocs, termContexts);
@@ -75,7 +75,7 @@
     // if there is no (positive) attributes, but there are *not attributes*
     // hasmorespan = true
     public SpansWithAttribute (SpanWithAttributeQuery spanWithAttributeQuery,
-                               AtomicReaderContext context, Bits acceptDocs,
+                               LeafReaderContext context, Bits acceptDocs,
                                Map<Term, TermContext> termContexts)
             throws IOException {
         super(spanWithAttributeQuery, context, acceptDocs, termContexts);
@@ -94,7 +94,7 @@
 
 
     public void setAttributeList (SpanWithAttributeQuery swaq,
-            AtomicReaderContext context, Bits acceptDocs,
+            LeafReaderContext context, Bits acceptDocs,
             Map<Term, TermContext> termContexts) throws IOException {
 
         attributeList = new ArrayList<AttributeSpans>();
@@ -141,7 +141,7 @@
      * @throws IOException
      */
     private void addAttributes (SpanAttributeQuery sq,
-            AtomicReaderContext context, Bits acceptDocs,
+            LeafReaderContext context, Bits acceptDocs,
             Map<Term, TermContext> termContexts) throws IOException {
 
         AttributeSpans as = (AttributeSpans) sq.getSpans(context, acceptDocs,
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/SubSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/SubSpans.java
index 6abec55..1bcfc40 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/SubSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/SubSpans.java
@@ -3,7 +3,7 @@
 import java.io.IOException;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.util.Bits;
@@ -36,7 +36,7 @@
      * @throws IOException
      */
     public SubSpans (SpanSubspanQuery subspanQuery,
-                     AtomicReaderContext context, Bits acceptDocs,
+                     LeafReaderContext context, Bits acceptDocs,
                      Map<Term, TermContext> termContexts) throws IOException {
         super(subspanQuery, context, acceptDocs, termContexts);
         this.startOffset = subspanQuery.getStartOffset();
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/TermSpansWithId.java b/src/main/java/de/ids_mannheim/korap/query/spans/TermSpansWithId.java
index 431b839..0135fca 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/TermSpansWithId.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/TermSpansWithId.java
@@ -5,7 +5,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.TermSpans;
@@ -40,7 +40,7 @@
      * @throws IOException
      */
     public TermSpansWithId (SpanTermWithIdQuery spanTermWithIdQuery,
-                            AtomicReaderContext context, Bits acceptDocs,
+                            LeafReaderContext context, Bits acceptDocs,
                             Map<Term, TermContext> termContexts)
             throws IOException {
         super(spanTermWithIdQuery, context, acceptDocs, termContexts);
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/TokenDistanceSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/TokenDistanceSpans.java
index 9044c5e..7eb0dfc 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/TokenDistanceSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/TokenDistanceSpans.java
@@ -5,7 +5,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.util.Bits;
@@ -38,7 +38,7 @@
      * @throws IOException
      */
     public TokenDistanceSpans (SpanDistanceQuery query,
-                               AtomicReaderContext context, Bits acceptDocs,
+                               LeafReaderContext context, Bits acceptDocs,
                                Map<Term, TermContext> termContexts)
             throws IOException {
         super(query, context, acceptDocs, termContexts);
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/UnorderedDistanceSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/UnorderedDistanceSpans.java
index 60e2a8a..705450d 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/UnorderedDistanceSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/UnorderedDistanceSpans.java
@@ -7,7 +7,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.Spans;
@@ -47,7 +47,7 @@
      * @throws IOException
      */
     public UnorderedDistanceSpans (SpanDistanceQuery query,
-                                   AtomicReaderContext context,
+                                   LeafReaderContext context,
                                    Bits acceptDocs,
                                    Map<Term, TermContext> termContexts)
             throws IOException {
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/UnorderedElementDistanceSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/UnorderedElementDistanceSpans.java
index 8489970..0fec0af 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/UnorderedElementDistanceSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/UnorderedElementDistanceSpans.java
@@ -6,7 +6,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.Spans;
@@ -50,7 +50,7 @@
      * @throws IOException
      */
     public UnorderedElementDistanceSpans (SpanDistanceQuery query,
-                                          AtomicReaderContext context,
+                                          LeafReaderContext context,
                                           Bits acceptDocs,
                                           Map<Term, TermContext> termContexts)
             throws IOException {
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/UnorderedTokenDistanceSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/UnorderedTokenDistanceSpans.java
index 0b8b055..a8013bb 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/UnorderedTokenDistanceSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/UnorderedTokenDistanceSpans.java
@@ -5,7 +5,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.Spans;
@@ -36,7 +36,7 @@
      * @throws IOException
      */
     public UnorderedTokenDistanceSpans (SpanDistanceQuery query,
-                                        AtomicReaderContext context,
+                                        LeafReaderContext context,
                                         Bits acceptDocs,
                                         Map<Term, TermContext> termContexts)
             throws IOException {
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/WithinSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/WithinSpans.java
index 4358f45..2afcc42 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/WithinSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/WithinSpans.java
@@ -6,7 +6,7 @@
 import java.util.LinkedList;
 import java.util.Map;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.DocIdSetIterator;
@@ -100,7 +100,7 @@
      * @param spanWithinQuery
      *            The parental {@link SpanWithinQuery}.
      * @param context
-     *            The {@link AtomicReaderContext}.
+     *            The {@link LeafReaderContext}.
      * @param acceptDocs
      *            Bit vector representing the documents
      *            to be searched in.
@@ -111,7 +111,7 @@
      *            the sub spans.
      */
     public WithinSpans (SpanWithinQuery spanWithinQuery,
-                        AtomicReaderContext context, Bits acceptDocs,
+                        LeafReaderContext context, Bits acceptDocs,
                         Map<Term, TermContext> termContexts, byte flag)
             throws IOException {
 
diff --git a/src/main/java/de/ids_mannheim/korap/response/Match.java b/src/main/java/de/ids_mannheim/korap/response/Match.java
index 617f07a..f5e3e63 100644
--- a/src/main/java/de/ids_mannheim/korap/response/Match.java
+++ b/src/main/java/de/ids_mannheim/korap/response/Match.java
@@ -5,7 +5,7 @@
 import java.util.*;
 
 import org.apache.lucene.document.Document;
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
 import org.apache.lucene.search.spans.Spans;
@@ -763,7 +763,7 @@
 
         if (this.positionsToOffset != null)
             return this.expandContextToSpan(
-                    this.positionsToOffset.getAtomicReader(), (Bits) null,
+                    this.positionsToOffset.getLeafReader(), (Bits) null,
                     "tokens", element);
         return new int[] { 0, 0, 0, 0 };
     };
@@ -771,7 +771,7 @@
 
     // Expand the context to a span
     // THIS IS NOT VERY CLEVER - MAKE IT MORE CLEVER!
-    public int[] expandContextToSpan (AtomicReaderContext atomic, Bits bitset,
+    public int[] expandContextToSpan (LeafReaderContext atomic, Bits bitset,
             String field, String element) {
 
         try {
@@ -1307,7 +1307,7 @@
             this.endMore = false;
 
             int[] spanContext = this.expandContextToSpan(
-                    this.positionsToOffset.getAtomicReader(), (Bits) null,
+                    this.positionsToOffset.getLeafReader(), (Bits) null,
                     "tokens", this.context.getSpanContext());
             startOffset = spanContext[0];
             endOffset = spanContext[1];
diff --git a/src/main/java/de/ids_mannheim/korap/server/Node.java b/src/main/java/de/ids_mannheim/korap/server/Node.java
index 19554e4..058cf33 100644
--- a/src/main/java/de/ids_mannheim/korap/server/Node.java
+++ b/src/main/java/de/ids_mannheim/korap/server/Node.java
@@ -3,6 +3,8 @@
 import java.util.*;
 import java.io.*;
 import java.net.URL;
+import java.nio.file.Paths;
+import java.nio.file.Path;
 
 import org.glassfish.grizzly.http.server.HttpServer;
 import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
@@ -278,10 +280,10 @@
 
             // Get a MMap directory index
             else {
-                File file = new File(path);
+                Path file = Paths.get(path);
 
                 log.info("Loading index from {}", path);
-                if (!file.exists()) {
+                if (!file.toFile().exists()) {
                     log.error("Index not found at {}", path);
                     return null;
                 };
diff --git a/src/main/java/de/ids_mannheim/korap/util/KrillByte.java b/src/main/java/de/ids_mannheim/korap/util/KrillByte.java
index 6ae3256..419a43f 100644
--- a/src/main/java/de/ids_mannheim/korap/util/KrillByte.java
+++ b/src/main/java/de/ids_mannheim/korap/util/KrillByte.java
@@ -19,6 +19,7 @@
      */
     // Based on
     // http://www.tutorials.de/java/228129-konvertierung-von-integer-byte-array.html
+    // CHECK: int2byte may be out of use
     public static byte[] int2byte (int number) {
         byte[] data = new byte[4];
         for (int i = 0; i < 4; ++i) {
diff --git a/src/test/java/de/ids_mannheim/korap/TestSimple.java b/src/test/java/de/ids_mannheim/korap/TestSimple.java
index abda3c8..9a42ab8 100644
--- a/src/test/java/de/ids_mannheim/korap/TestSimple.java
+++ b/src/test/java/de/ids_mannheim/korap/TestSimple.java
@@ -130,7 +130,7 @@
         Map<Term, TermContext> termContexts = new HashMap<>();
         List<String> spanArray = new ArrayList<>();
 
-        for (AtomicReaderContext atomic : reader.leaves()) {
+        for (LeafReaderContext atomic : reader.leaves()) {
             Bits bitset = atomic.reader().getLiveDocs();
             // Spans spans = NearSpansOrdered();
             Spans spans = query.getSpans(atomic, bitset, termContexts);
diff --git a/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkSpans.java b/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkSpans.java
index 922792e..6d7de11 100644
--- a/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkSpans.java
+++ b/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkSpans.java
@@ -21,6 +21,8 @@
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
 
+import java.nio.file.Paths;
+
 @RunWith(JUnit4.class)
 public class TestBenchmarkSpans {
 
@@ -32,7 +34,7 @@
         prop.load(fr);
 
         // Get the real index
-        KrillIndex ki = new KrillIndex(new MMapDirectory(new File(
+        KrillIndex ki = new KrillIndex(new MMapDirectory(Paths.get(
                 prop.getProperty("krill.indexDir"))));
 
         // Create a container for virtual collections:
@@ -86,7 +88,7 @@
         prop.load(fr);
 
         // Get the real index
-        KrillIndex ki = new KrillIndex(new MMapDirectory(new File(
+        KrillIndex ki = new KrillIndex(new MMapDirectory(Paths.get(
                 prop.getProperty("krill.indexDir"))));
 
         // Create a container for virtual collections:
@@ -132,7 +134,7 @@
         prop.load(fr);
 
         // Get the real index
-        KrillIndex ki = new KrillIndex(new MMapDirectory(new File(
+        KrillIndex ki = new KrillIndex(new MMapDirectory(Paths.get(
                 prop.getProperty("krill.indexDir"))));
 
         // Create a container for virtual collections:
@@ -178,7 +180,7 @@
         prop.load(fr);
 
         // Get the real index
-        KrillIndex ki = new KrillIndex(new MMapDirectory(new File(
+        KrillIndex ki = new KrillIndex(new MMapDirectory(Paths.get(
                 prop.getProperty("krill.indexDir"))));
 
         // Create a container for virtual collections:
@@ -324,7 +326,7 @@
         prop.load(fr);
 
         // Get the real index
-        KrillIndex ki = new KrillIndex(new MMapDirectory(new File(
+        KrillIndex ki = new KrillIndex(new MMapDirectory(Paths.get(
                 prop.getProperty("krill.indexDir"))));
 
         // Create a container for virtual collections:
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestIndex.java
index aac981e..9b08699 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestIndex.java
@@ -28,7 +28,7 @@
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.IndexWriterConfig;
 import org.apache.lucene.index.IndexWriterConfig.OpenMode;
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 
 import org.apache.lucene.queryparser.classic.ParseException;
 import org.apache.lucene.queryparser.classic.QueryParser;
@@ -196,15 +196,14 @@
     public void indexLucene () throws Exception {
 
         // Base analyzer for searching and indexing
-        StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_43);
+        StandardAnalyzer analyzer = new StandardAnalyzer();
 
         // Based on
         // http://lucene.apache.org/core/4_0_0/core/org/apache/lucene/
         // analysis/Analyzer.html?is-external=true
 
         // Create configuration with base analyzer
-        IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_43,
-                analyzer);
+        IndexWriterConfig config = new IndexWriterConfig(analyzer);
 
         // Add a document 1 with the correct fields
         IndexWriter w = new IndexWriter(index, config);
@@ -512,7 +511,7 @@
 
         StringBuilder payloadString = new StringBuilder();
         Map<Term, TermContext> termContexts = new HashMap<>();
-        for (AtomicReaderContext atomic : reader.leaves()) {
+        for (LeafReaderContext atomic : reader.leaves()) {
             Bits bitset = atomic.reader().getLiveDocs();
             //	    Spans spans = NearSpansOrdered();
             Spans spans = snquery.getSpans(atomic, bitset, termContexts);
@@ -547,7 +546,7 @@
 
         payloadString = new StringBuilder();
         termContexts = new HashMap<>();
-        for (AtomicReaderContext atomic : reader.leaves()) {
+        for (LeafReaderContext atomic : reader.leaves()) {
             Bits bitset = atomic.reader().getLiveDocs();
             //	    Spans spans = NearSpansOrdered();
             Spans spans = snquery.getSpans(atomic, bitset, termContexts);
@@ -576,7 +575,7 @@
 
         payloadString = new StringBuilder();
         termContexts = new HashMap<>();
-        for (AtomicReaderContext atomic : reader.leaves()) {
+        for (LeafReaderContext atomic : reader.leaves()) {
             Bits bitset = atomic.reader().getLiveDocs();
             // Spans spans = NearSpansOrdered();
             Spans spans = ssequery.toQuery().getSpans(atomic, bitset, termContexts);
@@ -601,7 +600,7 @@
 
         payloadString = new StringBuilder();
         termContexts = new HashMap<>();
-        for (AtomicReaderContext atomic : reader.leaves()) {
+        for (LeafReaderContext atomic : reader.leaves()) {
             Bits bitset = atomic.reader().getLiveDocs();
             // Spans spans = NearSpansOrdered();
             Spans spans = ssequery.toQuery().getSpans(atomic, bitset, termContexts);
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestPosToOffset.java b/src/test/java/de/ids_mannheim/korap/index/TestPosToOffset.java
index c31fa1f..1b0803a 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestPosToOffset.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestPosToOffset.java
@@ -20,13 +20,10 @@
 import de.ids_mannheim.korap.index.MultiTermTokenStream;
 import de.ids_mannheim.korap.index.PositionsToOffset;
 
-import org.apache.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.search.spans.SpanQuery;
 import org.apache.lucene.search.spans.SpanTermQuery;
 import org.apache.lucene.index.TermContext;
-import org.apache.lucene.util.OpenBitSet;
-import org.apache.lucene.search.DocIdSet;
-import org.apache.lucene.util.DocIdBitSet;
 import org.apache.lucene.util.Bits;
 
 import java.nio.ByteBuffer;
@@ -51,7 +48,7 @@
         ki.commit();
 
         String field = "base";
-        for (AtomicReaderContext atomic : ki.reader().leaves()) {
+        for (LeafReaderContext atomic : ki.reader().leaves()) {
             PositionsToOffset pto = new PositionsToOffset(atomic, field);
 
             pto.add(0, 1);
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestRealIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestRealIndex.java
index 837da00..09fd4a5 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestRealIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestRealIndex.java
@@ -17,6 +17,7 @@
 import de.ids_mannheim.korap.response.Result;
 import de.ids_mannheim.korap.query.QueryBuilder;
 import de.ids_mannheim.korap.util.QueryException;
+import java.nio.file.Paths;
 
 public class TestRealIndex {
     KrillIndex ki;
@@ -31,7 +32,7 @@
 
         String indexPath = prop.getProperty("lucene.indexDir");
         System.err.println(indexPath);
-        MMapDirectory md = new MMapDirectory(new File(indexPath));
+        MMapDirectory md = new MMapDirectory(Paths.get(indexPath));
         ki = new KrillIndex(md);
     };
 
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestRelationIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestRelationIndex.java
index 8618592..22cbc67 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestRelationIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestRelationIndex.java
@@ -95,7 +95,7 @@
         fd.addTV(
                 "base",
                 "ceccecdeed",
-                "[(0-1)s:c$<s>2|<>:p$#0-3$<i>3<s>1|_0#0-1|"
+                "[(0-1)s:c$<s>2|<>:p#0-3$<i>3<s>1|_0#0-1|"
                         + ">:xip/syntax-dep_rel$<i>3<i>6<i>9<s>2<s>1<s>1|"
                         + ">:xip/syntax-dep_rel$<i>6<i>9<s>1<s>2<s>1|"
                         + "r@:func=subj$<s>2]"
@@ -104,7 +104,7 @@
                         + "[(3-4)s:c|s:b|_3#3-4]"
                         + "[(4-5)s:e|s:d|_4#4-5]"
                         + "[(5-6)s:c|_5#5-6]"
-                        + "[(6-7)s:d$<s>2|<>:p$#6-9$<i>9<s>1|_6#6-7|"
+                        + "[(6-7)s:d$<s>2|<>:p#6-9$<i>9<s>1|_6#6-7|"
                         + "<:xip/syntax-dep_rel$<i>9<b>0<i>1<s>1<s>1<s>2|"
                         + ">:xip/syntax-dep_rel$<i>9<b>0<i>9<s>3<s>1<s>1|"
                         + "<:xip/syntax-dep_rel$<i>9<i>1<i>3<s>2<s>1<s>1|"
@@ -634,5 +634,4 @@
         assertEquals(4, kr.getMatch(3).getStartPos());
         assertEquals(7, kr.getMatch(3).getEndPos());
     }
-
-}
\ No newline at end of file
+}
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestWPDIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestWPDIndex.java
index 3b96e13..a9fd222 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestWPDIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestWPDIndex.java
@@ -25,6 +25,8 @@
 import de.ids_mannheim.korap.query.SpanNextQuery;
 import de.ids_mannheim.korap.query.SpanRepetitionQuery;
 
+import java.nio.file.Paths;
+
 public class TestWPDIndex {
     long start, end;
     KrillIndex ki;
@@ -60,7 +62,7 @@
         prop.load(is);
 
         String indexPath = prop.getProperty("lucene.indexDir");
-        MMapDirectory md = new MMapDirectory(new File(indexPath));
+        MMapDirectory md = new MMapDirectory(Paths.get(indexPath));
         ki = new KrillIndex(md);
     }