Some class payload fixes / not finished yet

Change-Id: I82328d9f94b96faeec666eec247b914d5df501c6
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 0b189d0..b785d2e 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
@@ -93,6 +93,7 @@
         int start, end;
         // System.out.println("------------------------");
         for (byte[] payload : firstSpans.getPayload()) {
+            /*
             System.err.println(
                                "** " +
                                payload[0] +
@@ -103,6 +104,7 @@
                                "|" +
                                payload[8] +
                                " **");
+            */
             if (payload[0] == 0) {
                 start = byte2int(payload, 1) + 1;
                 end = byte2int(payload, 5) + 1;
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 bb49e6a..16878f4 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
@@ -148,6 +148,7 @@
         // Todo: Better allocate using a Factory!
         bb.clear();
         bb.put((byte) 0).putInt(spans.start()).putInt(spans.end()).put(number);
+        /*
         System.err.println(
                            "####################### " + 
                            spans.start() +
@@ -156,6 +157,7 @@
                            ":" +
                            number
                            );
+        */
 
         // Add highlight information as byte array
         classedPayload.add(bb.array());
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 10d740c..b134c72 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
@@ -165,12 +165,16 @@
         for (byte[] payload : firstSpans.getPayload()) {
             // No class payload - ignore
             // this may be problematic for other calculated payloads!
+            /*
             if ((!matchTemporaryClass && payload.length == 9)
                     || (matchTemporaryClass && payload.length == 10)) {
-                if (classNumbers.contains(payload[8])) {
+            */
+
+            if (payload[0] == 0) {
+                if (classNumbers.contains(payload[9])) {
                     isClassFound = true;
-                    classStart = byte2int(payload, 0);
-                    classEnd = byte2int(payload, 4);
+                    classStart = byte2int(payload, 1);
+                    classEnd = byte2int(payload, 5);
 
                     if (isStart || classStart < minPos) {
                         minPos = classStart;
@@ -180,12 +184,19 @@
                         maxPos = classEnd;
                     }
                 }
-            }
 
+                if (removeTemporaryClasses) {
+                    continue;
+                };
+            }
+        
+            /*
             if (payload.length == 8
                     || (removeTemporaryClasses && payload.length == 10)) {
                 continue;
             }
+            */
+
             candidateSpan.getPayloads().add(payload.clone());
         }
 
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 865cef9..1f2e338 100644
--- a/src/main/java/de/ids_mannheim/korap/response/Match.java
+++ b/src/main/java/de/ids_mannheim/korap/response/Match.java
@@ -221,7 +221,8 @@
         // Reverse to make embedding of highlights correct
         Collections.reverse(payload);
         try {
-            ByteBuffer bb = ByteBuffer.allocate(10);
+
+            ByteBuffer bb = ByteBuffer.allocate(24);
 
             // TODO: REVERSE ITERATOR!
             for (byte[] b : payload) {
@@ -255,20 +256,21 @@
 
                 // Element payload for match!
                 // This MAY BE the correct match
-                else if (b[0] == 64) {
+                else if (b[0] == (byte) 64) {
+
                     bb.put(b);
-                    bb.position(1);
+
 
                     if (this.potentialStartPosChar == -1) {
-                        this.potentialStartPosChar = bb.getInt(0);
+                        this.potentialStartPosChar = bb.getInt(1);
                     }
                     else {
                         if (bb.getInt(0) < this.potentialStartPosChar)
-                            this.potentialStartPosChar = bb.getInt(0);
+                            this.potentialStartPosChar = bb.getInt(1);
                     };
 
                     if (bb.getInt(4) > this.potentialEndPosChar)
-                        this.potentialEndPosChar = bb.getInt(4);
+                        this.potentialEndPosChar = bb.getInt(5);
 
                     if (DEBUG)
                         log.trace("Element payload from {} to {}",
@@ -903,6 +905,7 @@
         if (processed)
             return true;
 
+
         // Relevant details are missing
         if (this.positionsToOffset == null || this.localDocID == -1) {
             log.warn("You have to define "
@@ -1138,6 +1141,7 @@
             sb.append("... ");
 
         for (HighlightCombinatorElement hce : this.snippetArray.list()) {
+
             sb.append(hce.toBrackets(this));
         };
 
diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties
index d99b63c..850a404 100644
--- a/src/main/resources/log4j.properties
+++ b/src/main/resources/log4j.properties
@@ -25,7 +25,7 @@
 
 # Responses:
 # log4j.logger.de.ids_mannheim.korap.server.Node = TRACE, stdout
-log4j.logger.de.ids_mannheim.korap.response.Match = TRACE, stdout
+# log4j.logger.de.ids_mannheim.korap.response.Match = TRACE, stdout
 
 # Index:
 log4j.logger.de.ids_mannheim.korap.KrillIndex = TRACE, stdout
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestClassFilterIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestClassFilterIndex.java
index c87f13a..4abea57 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestClassFilterIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestClassFilterIndex.java
@@ -105,9 +105,11 @@
         // }
         assertEquals(0, kr.getMatch(0).getStartPos());
         assertEquals(5, kr.getMatch(0).getEndPos());
+
         assertEquals(
                 "[{1:Frankenstein}, {2:treat my daughter well}]. She is the one that saved ...",
                 kr.getMatch(0).getSnippetBrackets());
+
         assertEquals(1, kr.getMatch(1).getStartPos());
         assertEquals(6, kr.getMatch(1).getEndPos());
         assertEquals(
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestMatchIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestMatchIndex.java
index 737fabb..7ca253f 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestMatchIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestMatchIndex.java
@@ -414,6 +414,10 @@
         kr = ki.search(sq, (short) 10);
         assertEquals(kr.getSerialQuery(),
                 "focus(3: spanContain({2: <base:s />}, {3: base:s:b}))");
+
+        System.err.println(kr.getMatch(0).getSnippetBrackets());
+
+
         assertEquals(kr.getMatch(0).getSnippetBrackets(), "a[{3:b}]cabcab ...");
     };