Fixed skipTo in NextSpans.

Change-Id: I526a2a3a2720d680bc61e6b2939a61246f918012
diff --git a/Changes b/Changes
index 56cf451..e6c2849 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,4 @@
-0.58.1 2018-11-02
+0.58.1 2018-11-12
     - [bugfix] Security upgrade of Jackson for CVE-2017-17485 and
       CVE-2018-7489 (diewald)
     - [bugfix] Span expansion with negation (margaretha)
@@ -7,6 +7,8 @@
     - [feature] Helper methods for fuzzing (diewald)
     - [bugfix] Remove entries from matchList that are not in the same
       document in NextSpans (diewald)
+    - [bugfix] Fixed skipTo in NextSpans, see de.ids_mannheim.korap.index.
+      TestRepetitionIndex.testRepetitionSnippetBug3() (margaretha)  
 
 0.58.0 2018-09-03
     - [feature] Implemented referencing cached collection (margaretha)
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/CandidateSpan.java b/src/main/java/de/ids_mannheim/korap/query/spans/CandidateSpan.java
index fcdb6ff..8049782 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/CandidateSpan.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/CandidateSpan.java
@@ -409,4 +409,9 @@
         else
             return 1;
     }
+    
+    @Override
+    public String toString () {
+        return getClass().getName() + "@" +doc + ":" + start + "-" + end;
+    }
 }
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 8a22191..2ea1377 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
@@ -116,8 +116,9 @@
             }
             // Forward firstspan
             hasMoreFirstSpan = firstSpans.next();
-            if (hasMoreFirstSpan)
+            if (hasMoreFirstSpan){
                 setMatchList();
+            }
             else {
                 hasMoreSpans = false;
                 candidateList.clear();
@@ -269,6 +270,13 @@
             };
         }
         matchPayload.clear();
+        if (hasMoreFirstSpan){
+            setMatchList();
+        }
+        else {
+            hasMoreSpans = false;
+            candidateList.clear();
+        }
         return advance();
     }
 
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 7e57a80..2698133 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
@@ -72,10 +72,8 @@
 
     /**
      * Advances the RepetitionSpans to the next match by setting the
-     * first
-     * element in the matchlist as the current match. When the
-     * matchlist is
-     * empty, it has to be set first.
+     * first element in the matchlist as the current match. When the
+     * matchlist is empty, it has to be set first.
      * 
      * @return <code>true</code> if a match is found,
      *         <code>false</code>
@@ -104,7 +102,8 @@
 
 
     /**
-     * Collects all adjacent firstspans occurring in a sequence.
+     * Collects all adjacent firstspans occurring in a sequence 
+     * in the same document.
      * 
      * @return a list of the adjacent spans
      * @throws IOException
@@ -173,8 +172,7 @@
 
     /**
      * Generates all possible repetition match spans from the given
-     * list of
-     * adjacent spans and add them to the match list.
+     * list of adjacent spans and add them to the match list.
      * 
      * @param adjacentSpans
      */
@@ -230,12 +228,6 @@
                 }
                 j++;
             }
-
-            /*
-            if (j + i == adjacentSpans.size()) {
-
-            }
-            */
         }
 
         Collections.sort(matchList);
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestRepetitionIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestRepetitionIndex.java
index 762c907..4478295 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestRepetitionIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestRepetitionIndex.java
@@ -385,7 +385,6 @@
     };
 
     @Test
-    @Ignore
     public void testRepetitionSnippetBug3 () throws IOException, QueryException {
         // Construct index
         Pattern p = Pattern.compile("bccc?d");