Create failing test for startswith-bug

Change-Id: I6ee1f9815d37717acc95e925420beb4391a80c38
diff --git a/src/main/java/de/ids_mannheim/korap/KrillIndex.java b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
index 44528f0..e4535c0 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
@@ -118,7 +118,7 @@
     // TODO: Use configuration instead.
     // Last line of defense against DOS
     private int autoCommit = 500;
-    private String version = "unknown";
+    private String version = "Unknown";
     private String name = "Unknown";
 
     // Temp:
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 8227bda..ba056d1 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
@@ -77,12 +77,17 @@
         super(spanElementQuery, context, acceptDocs, termContexts);
         termSpans = (TermSpans) this.firstSpans;
         hasMoreSpans = true;
-        // termSpans.next();
+        if (DEBUG)
+            log.trace("Create ElementSpan");
     };
 
 
     @Override
     public boolean next () throws IOException {
+
+        if (DEBUG)
+            log.trace("Next element span for element");
+
         if (!hasMoreSpans || !(hasMoreSpans = termSpans.next()))
             return false;
 
@@ -94,8 +99,6 @@
 
 
     private boolean advance () throws IOException {
-
-
         this.matchStartPosition = termSpans.start();
         this.matchDocNumber = termSpans.doc();
         isPayloadLoaded = false;
diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties
index fd0328d..78bf62e 100644
--- a/src/main/resources/log4j.properties
+++ b/src/main/resources/log4j.properties
@@ -1,4 +1,4 @@
-# log4j.rootLogger = ERROR, stdout
+log4j.rootLogger = ERROR, stdout
 
 # Queries:
 # log4j.logger.de.ids_mannheim.korap.query.SpanNextQuery = TRACE, stdout
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestWithinIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestWithinIndex.java
index b85206e..ce6dac3 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestWithinIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestWithinIndex.java
@@ -16,8 +16,10 @@
 
 import de.ids_mannheim.korap.KrillIndex;
 import de.ids_mannheim.korap.KrillQuery;
+import de.ids_mannheim.korap.query.QueryBuilder;
 import de.ids_mannheim.korap.query.SpanClassQuery;
 import de.ids_mannheim.korap.query.SpanElementQuery;
+import de.ids_mannheim.korap.query.wrap.SpanQueryWrapper;
 import de.ids_mannheim.korap.query.SpanNextQuery;
 import de.ids_mannheim.korap.query.SpanWithinQuery;
 import de.ids_mannheim.korap.query.wrap.SpanQueryWrapper;
@@ -1055,14 +1057,14 @@
 
     /** SpanElementQueries */
     @Test
-    public void indexExample8 () throws IOException {
+    public void indexExample8 () throws QueryException, IOException {
         KrillIndex ki = new KrillIndex();
         FieldDocument fd = new FieldDocument();
         // <a>xx <e>hi j <e>hi j</e></e></a>
         fd.addTV(
                 "base",
                 "xx hi j hi j",
-                "[(0-1)s:x|i:x|_0$<i>0<i>1|<>:a$<b>64<i>1<i>12<i>8<b>0]"
+                "[(0-1)s:x|i:x|_0$<i>0<i>1|<>:a$<b>64<i>0<i>12<i>8<b>0]"
                         + "[(1-2)s:x|i:x|_1$<i>1<i>2]"
                         + "[(3-4)s:h|i:h|_2$<i>3<i>4|<>:e$<b>64<i>3<i>12<i>8<b>0]"
                         + "[(4-5)s:i|i:i|_3$<i>4<i>5]"
@@ -1071,8 +1073,30 @@
                         + "[(9-10)s:i|i:i|_6$<i>9<i>10]"
                         + "[(11-12)s:j|i:j|_7$<i>11<i>12]");
         ki.addDoc(fd);
+        ki.commit();
 
-        // TODO!!
+        assertEquals(1, ki.numberOf("documents"));
+
+        QueryBuilder qb = new KrillQuery("base").builder();
+        SpanQueryWrapper sqw = qb.seg("i:x");
+        Result kr = ki.search(sqw.toQuery(), (short) 10);
+        assertEquals(2, kr.getTotalResults());
+
+        sqw = qb.tag("a");
+        kr = ki.search(sqw.toQuery(), (short) 10);
+        assertEquals(1, kr.getTotalResults());
+
+        sqw = qb.startswith(qb.tag("a"), qb.seg("i:x"));
+        assertEquals("spanStartsWith(<base:a />, base:i:x)",
+                     sqw.toQuery().toString());
+        kr = ki.search(sqw.toQuery(), (short) 10);
+        assertEquals(1, kr.getTotalResults());
+
+        sqw = qb.startswith(qb.tag("e"), qb.seg("i:h"));
+        assertEquals("spanStartsWith(<base:e />, base:i:h)",
+                     sqw.toQuery().toString());
+        kr = ki.search(sqw.toQuery(), (short) 10);
+        assertEquals(2, kr.getTotalResults());
     };