Fixed major lazy loading bug in WithinSpans

Change-Id: I67f1cfb0c5fa2660c790bc9f3988a3db0d24af95
diff --git a/src/main/java/de/ids_mannheim/korap/KrillIndex.java b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
index 7338472..1ed2b33 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
@@ -114,7 +114,7 @@
     private final static Logger log = LoggerFactory.getLogger(KrillIndex.class);
 
     // This advices the java compiler to ignore all loggings
-    public static final boolean DEBUG = true;
+    public static final boolean DEBUG = false;
 
     // TODO: Use configuration instead.
     // Last line of defense against DOS
@@ -1361,11 +1361,11 @@
 
                     if (DEBUG) {
                         if (match.getDocID() != null)
-                            log.trace("I've got a match in {} of {}",
-                                    match.getDocID(), count);
+                            log.trace("With DocID: I've got 1 match of {} in {}",
+                                      count, match.getDocID());
                         else
-                            log.trace("I've got a match in {} of {}",
-                                    match.getUID(), count);
+                            log.trace("With UID: I've got 1 match of {} in {}",
+                                      count, match.getUID());
                     };
 
                     atomicMatches.add(match);
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 539c331..63c665e 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
@@ -655,7 +655,6 @@
 
         if (this.embeddedStart == -1) {
             this.embeddedStart = this.embeddedSpans.start();
-            this.embeddedEnd = this.embeddedSpans.end();
         };
 
         this.wrapEnd = -1;
@@ -687,6 +686,10 @@
             };
         };
 
+        if (this.embeddedEnd == -1) {
+            this.embeddedEnd = this.embeddedSpans.end();
+        };
+
         // Now check correctly
         byte currentCase = this.withinCase();
 
@@ -935,6 +938,15 @@
     // Return case number
     private byte withinCase () {
 
+        if (DEBUG) {
+            log.trace(">>>>>>>>>>>>>> {}-{}|{}-{}",
+                      this.wrapStart,
+                      this.wrapSpans.end(),
+                      this.embeddedStart,
+                      this.embeddedSpans.end()
+                      );
+        };
+
         // case 1-5
         if (this.wrapStart > this.embeddedStart) {
 
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 922f9ae..4bb289a 100644
--- a/src/main/java/de/ids_mannheim/korap/response/Match.java
+++ b/src/main/java/de/ids_mannheim/korap/response/Match.java
@@ -251,7 +251,11 @@
                     // TODO: This may be decidable by PTI!
                     if (unsignedByte(number) <= 128 && start >= this.getStartPos()
                             && end <= this.getEndPos()) {
-                        log.trace("Add highlight of class {}!", unsignedByte(number));
+
+                        if (DEBUG) {
+                            log.trace("Add highlight of class {}!", unsignedByte(number));
+                        };
+
                         this.addHighlight(start, end - 1, number);
                     }
                     else if (DEBUG) {
diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties
index b8bf604..5fed33b 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
@@ -28,9 +28,9 @@
 # log4j.logger.de.ids_mannheim.korap.response.Match = TRACE, stdout
 
 # Index:
-log4j.logger.de.ids_mannheim.korap.KrillIndex = TRACE, stdout
-log4j.logger.de.ids_mannheim.korap.index.PositionsToOffset = TRACE, stdout
-log4j.logger.de.ids_mannheim.korap.index.MultiTermTokenStream = TRACE, stdout
+# log4j.logger.de.ids_mannheim.korap.KrillIndex = TRACE, stdout
+# log4j.logger.de.ids_mannheim.korap.index.PositionsToOffset = TRACE, stdout
+# log4j.logger.de.ids_mannheim.korap.index.MultiTermTokenStream = TRACE, stdout
 
 # Tests:
 # log4j.logger.de.ids_mannheim.korap.index.TestSegmentIndex = TRACE, stdout
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 ee6c20b..423645e 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestSpanExpansionIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestSpanExpansionIndex.java
@@ -31,14 +31,12 @@
     Result kr;
     KrillIndex ki;
 
-
     public TestSpanExpansionIndex () throws IOException {
         ki = new KrillIndex();
         ki.addDoc(getClass().getResourceAsStream("/wiki/00001.json.gz"), true);
         ki.commit();
     }
 
-
     /**
      * Left and right expansions
      * */
@@ -385,10 +383,10 @@
         assertEquals("[ca]b",kr.getMatch(1).getSnippetBrackets());
         assertEquals("[cab]",kr.getMatch(2).getSnippetBrackets());
         assertEquals("[c]e",kr.getMatch(3).getSnippetBrackets());
-        /*
+
         assertEquals("[ce]",kr.getMatch(4).getSnippetBrackets());
         assertEquals(5, kr.getTotalResults());
-        */
+
         sq = kq.builder().tag("base/s:t").toQuery();
         assertEquals(sq.toString(),"<base:base/s:t />");
         kr = ki.search(sq, (short) 5);