Fixed left expansion of SpanOR exclusion in case of no more span.
diff --git a/Changes b/Changes
index 35f3e02..3b0b09c 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,4 @@
-0.56.2 2018-03-07
+0.56.2 2018-03-20
         - [feature] Introduce meta field retrieval method (diewald)
         - [cleanup] Rename KrillQuery's "_"-method to "nr" to improve
           compatibility with future versions of Java (diewald)
@@ -12,6 +12,8 @@
           indexed properly (may require reindexing; diewald)
         - [feature] Serialize dates in dash separation format, when
           metadata field name ends with "Date" (diewald)
+        - [bugfix] Fixed left exclusion-expansion when there is no 
+          more span for SpanOrQuery (margaretha) 
 
 0.56.1 2018-01-31
         - [bugfix] Changed relation serialization in snippet to work
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 d747149..daea9e8 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
@@ -150,8 +150,7 @@
                 }
                 break;
             }
-            else if (!notClause.next())
-                hasMoreNotClause = false;
+            else if (!notClause.next()) hasMoreNotClause = false;
         }
     }
 
@@ -173,15 +172,16 @@
                 lastNotClause = new CandidateSpan(notClause);
                 //counter--;
             }
-            if (!notClause.next())
+            if (!notClause.next()) {
                 hasMoreNotClause = false;
+            }
         }
 
         // if a notClause is between max and firstspan.start, 
         // then maxPos = last NotClause pos -1
         generateCandidates(min, maxPos, direction);
 
-        if (lastNotClause != null)
+        if (lastNotClause != null && hasMoreNotClause)
             while ((hasMoreSpans = firstSpans.next())
                     // the next notClause is not in between max and firstspan.start()
                     && notClause.start() > firstSpans.start()
@@ -192,8 +192,9 @@
                 maxPos = firstSpans.start() - lastNotClause.getStart() - 1;
                 generateCandidates(min, maxPos, direction);
             }
-        else
+        else {
             hasMoreSpans = firstSpans.next();
+        }
     }
 
 
@@ -216,8 +217,9 @@
                 firstNotClause = new CandidateSpan(notClause);
                 isFound = true;
             }
-            if (!notClause.next())
+            if (!notClause.next()) {
                 hasMoreNotClause = false;
+            }
         }
         // if a notClause is between firstSpan.end and max
         // then maxPos = the first notClause pos -1 
@@ -233,8 +235,9 @@
                 generateCandidates(min, maxPos, direction);
             }
         }
-        else
+        else {
             hasMoreSpans = firstSpans.next();
+        }
     }
 
 
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestSpanExpansionIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestSpanExpansionIndex.java
index 757e2cc..579ae82 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestSpanExpansionIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestSpanExpansionIndex.java
@@ -22,10 +22,11 @@
 import de.ids_mannheim.korap.query.QueryBuilder;
 import de.ids_mannheim.korap.query.SpanElementQuery;
 import de.ids_mannheim.korap.query.SpanExpansionQuery;
+import de.ids_mannheim.korap.query.SpanNextQuery;
 import de.ids_mannheim.korap.query.SpanRepetitionQuery;
 import de.ids_mannheim.korap.query.wrap.SpanQueryWrapper;
-import de.ids_mannheim.korap.response.Result;
 import de.ids_mannheim.korap.response.Match;
+import de.ids_mannheim.korap.response.Result;
 import de.ids_mannheim.korap.util.QueryException;
 
 public class TestSpanExpansionIndex {
@@ -147,8 +148,8 @@
     public void testCase3 () throws IOException {
         byte classNumber = 1;
         SpanTermQuery stq = new SpanTermQuery(new Term("tokens", "tt/p:NN"));
-        SpanTermQuery notQuery = new SpanTermQuery(
-                new Term("tokens", "s:Buchstabe"));
+        SpanTermQuery notQuery =
+                new SpanTermQuery(new Term("tokens", "s:Buchstabe"));
 
         SpanExpansionQuery seq = new SpanExpansionQuery(stq, notQuery, 2, 3, 0,
                 classNumber, true);
@@ -183,8 +184,8 @@
     public void testCase4 () throws IOException {
         byte classNumber = 1;
         SpanTermQuery stq = new SpanTermQuery(new Term("tokens", "tt/p:NN"));
-        SpanTermQuery notQuery = new SpanTermQuery(
-                new Term("tokens", "tt/p:ADJA"));
+        SpanTermQuery notQuery =
+                new SpanTermQuery(new Term("tokens", "tt/p:ADJA"));
 
         SpanExpansionQuery seq = new SpanExpansionQuery(stq, notQuery, 0, 2, -1,
                 classNumber, true);
@@ -272,8 +273,8 @@
         SpanTermQuery stq = new SpanTermQuery(new Term("base", "s:e"));
         SpanTermQuery notQuery = new SpanTermQuery(new Term("base", "s:d"));
 
-        SpanExpansionQuery seq = new SpanExpansionQuery(stq, notQuery, 2, 3, 0,
-                true);
+        SpanExpansionQuery seq =
+                new SpanExpansionQuery(stq, notQuery, 2, 3, 0, true);
         kr = ki.search(seq, (short) 20);
 
         // notClause.doc() > firstSpans.doc()
@@ -336,10 +337,10 @@
         ki.commit();
 
         // See /queries/bugs/repetition_group_rewrite
-        RegexpQuery requery = new RegexpQuery(new Term("base", "s:[ac]"),
-                RegExp.ALL);
-        SpanMultiTermQueryWrapper<RegexpQuery> query = new SpanMultiTermQueryWrapper<RegexpQuery>(
-                requery);
+        RegexpQuery requery =
+                new RegexpQuery(new Term("base", "s:[ac]"), RegExp.ALL);
+        SpanMultiTermQueryWrapper<RegexpQuery> query =
+                new SpanMultiTermQueryWrapper<RegexpQuery>(requery);
         SpanExpansionQuery seq = new SpanExpansionQuery(query, 1, 1, 1, true);
         SpanRepetitionQuery rep = new SpanRepetitionQuery(seq, 2, 2, true);
 
@@ -379,16 +380,6 @@
 
         kr = ki.search(rep, (short) 20);
 
-        // for (Match km : kr.getMatches()){
-        // System.out.println(
-        // km.getStartPos() +
-        // "," +
-        // km.getEndPos() +
-        // " " +
-        // km.getSnippetBrackets()
-        // );
-        // };
-
         assertEquals("[[cecc]]ecdeec", kr.getMatch(0).getSnippetBrackets());
         assertEquals("cec[[cecd]]eec", kr.getMatch(1).getSnippetBrackets());
         assertEquals((long) 2, kr.getTotalResults());
@@ -434,7 +425,7 @@
     }
 
 
-	@Test
+    @Test
     public void indexRegexSequence () throws Exception {
         KrillIndex ki = new KrillIndex();
         ki.addDoc(createFieldDoc5());
@@ -442,40 +433,70 @@
 
         QueryBuilder kq = new QueryBuilder("base");
 
-		SpanQueryWrapper sq = kq.seq(
-			kq.or("s:baumgarten", "s:steingarten")
-			).append(kq.seg().without(kq.or("s:franz", "s:hans")));
-		
+        SpanQueryWrapper sq = kq.seq(kq.or("s:baumgarten", "s:steingarten"))
+                .append(kq.seg().without(kq.or("s:franz", "s:hans")));
 
-		// Expected to find [baumgarten steingarten]
-		Krill ks = _newKrill(sq);
+
+        // Expected to find [baumgarten steingarten]
+        Krill ks = _newKrill(sq);
         Result kr = ki.search(ks);
 
         assertEquals((long) 1, kr.getTotalResults());
 
         assertEquals("... baum [[baumgarten steingarten]] franz ...",
-					 kr.getMatch(0).getSnippetBrackets());
+                kr.getMatch(0).getSnippetBrackets());
 
-		// The same result should be shown for:
+        // The same result should be shown for:
 
-		sq = kq.seq(
-			kq.re("s:.*garten")
-			).append(
-				kq.seg().without(
-					kq.re("s:.*an.*")
-					)
-				);
+        sq = kq.seq(kq.re("s:.*garten"))
+                .append(kq.seg().without(kq.re("s:.*an.*")));
 
-		ks = _newKrill(sq);
+        ks = _newKrill(sq);
         kr = ki.search(ks);
 
         assertEquals((long) 1, kr.getTotalResults());
 
         assertEquals("... baum [[baumgarten steingarten]] franz ...",
-					 kr.getMatch(0).getSnippetBrackets());
-	};
-	
+                kr.getMatch(0).getSnippetBrackets());
+    };
 
+    @Test
+    public void testBugRegexExpandLeftNoMoreSpan () throws IOException {
+        KrillIndex ki = new KrillIndex();
+        ki.addDoc(createFieldDoc6());
+        ki.commit();
+
+        SpanTermQuery stq = new SpanTermQuery(new Term("base", "s:a"));
+        
+        RegexpQuery requery =
+                new RegexpQuery(new Term("base", "s:[bc]"), RegExp.ALL);
+        SpanMultiTermQueryWrapper<RegexpQuery> notQuery =
+                new SpanMultiTermQueryWrapper<RegexpQuery>(requery);
+
+        byte classNumber = 1;
+        // left expansion
+        SpanExpansionQuery seq = new SpanExpansionQuery(stq, notQuery, 0, 1, -1,
+                classNumber, true);
+
+        kr = ki.search(seq, (short) 20);
+
+        assertEquals(9,kr.getMatches().size());
+        
+    }
+
+    private FieldDocument createFieldDoc6 () {
+        FieldDocument fd = new FieldDocument();
+        fd.addString("ID", "doc-6");
+        fd.addTV("base", "baaaaaa",
+                "[(0-1)s:b|_0$<i>0<i>1|<>:base/s:t$<b>64<i>0<i>10<i>10<b>0]"
+                        + "[(1-2)s:a|_1$<i>1<i>2]" + "[(2-3)s:c|_2$<i>2<i>3]"
+                        + "[(3-4)s:a|s:d|_3$<i>3<i>4]"
+                        + "[(4-5)s:a|_4$<i>4<i>5]" + "[(5-6)s:c|_5$<i>5<i>6]"
+                        + "[(6-7)s:a|_6$<i>6<i>7]" + "[(7-8)s:d|_7$<i>7<i>8]"
+                        + "[(8-9)s:a|_8$<i>8<i>9]"
+                        + "[(9-10)s:a|_9$<i>9<i>10]");
+        return fd;
+    }
 
     private FieldDocument createFieldDoc0 () {
         FieldDocument fd = new FieldDocument();
@@ -534,7 +555,7 @@
         return fd;
     }
 
-	private FieldDocument createFieldDoc5 () {
+    private FieldDocument createFieldDoc5 () {
         FieldDocument fd = new FieldDocument();
         fd.addString("ID", "doc-5");
         fd.addTV("base",