Removed payloadReader
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 bbe9f59..f366b84 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
@@ -111,32 +111,25 @@
* @author margaretha
* */
private void readPayload(CandidateElementSpans cs) throws IOException {
- List<byte[]> payloadList = (List<byte[]>) termSpans.getPayload();
- BytesRef payload = new BytesRef(payloadList.get(0));
- //.getPostings().getPayload();
- //ByteBuffer payloadBuffer = ByteBuffer.allocate(128);
-
- if (payload != null) {
- // Copy some payloads like start character and end character
- //payloadBuffer.put(payload.bytes, payload.offset, 8);
+ List<byte[]> payload = (List<byte[]>) termSpans.getPayload();
+ int length = payload.get(0).length;
+ ByteBuffer bb = ByteBuffer.allocate(length);
+ bb.put(payload.get(0));
+
+ if (!payload.isEmpty()) {
+ // set element end position from payload
+ cs.setEnd(bb.getInt(8));
- cs.setEnd(PayloadReader.readInteger(payload,8));
-
- if (hasSpanId){
- // Copy rest of payloads after the end position and elementref
- //payloadBuffer.put(payload.bytes, payload.offset + 14, payload.length - 14);
- cs.setSpanId(PayloadReader.readShort(payload,12));
+ if (hasSpanId){ // copy element id
+ cs.setSpanId(bb.getShort(12));
}
- else{
- // Copy rest of payloads after the end position
- //payloadBuffer.put(payload.bytes, payload.offset + 12, payload.length - 12);
+ else{ // set element id -1
cs.setSpanId((short) -1);
}
-
- //byte[] offsetCharacters = new byte[8];
- //System.arraycopy(payloadBuffer.array(), 0, offsetCharacters, 0, 8);
-
- cs.setPayloads(Collections.singletonList(PayloadReader.readOffset(payload)));
+ // Copy the start and end character offsets
+ byte[] b = new byte[8];
+ System.arraycopy(bb.array(), 0, b, 0, 8);
+ cs.setPayloads(Collections.singletonList(b));
}
else {
cs.setEnd(cs.getStart());
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/PayloadReader.java b/src/main/java/de/ids_mannheim/korap/query/spans/PayloadReader.java
deleted file mode 100644
index a69a6d5..0000000
--- a/src/main/java/de/ids_mannheim/korap/query/spans/PayloadReader.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package de.ids_mannheim.korap.query.spans;
-
-import java.nio.ByteBuffer;
-
-import org.apache.lucene.util.BytesRef;
-
-public class PayloadReader {
-
- /** Get the offset bytes from the payload.
- * */
- public static byte[] readOffset(BytesRef payload){
- byte[] b = new byte[8];
- System.arraycopy(payload.bytes, payload.offset, b, 0, 8);
- return b;
- }
-
- /** Get the end position bytes from the payload and cast it to int.
- * */
- public static int readInteger(BytesRef payload, int start) {
- byte[] b = new byte[4];
- System.arraycopy(payload.bytes, payload.offset + start, b, 0, 4);
- return ByteBuffer.wrap(b).getInt();
- }
-
- /** Get the elementRef bytes from the payload and cast it into short.
- * */
- public static short readShort(BytesRef payload, int start) {
- byte[] b = new byte[2];
- System.arraycopy(payload.bytes, payload.offset + start, b, 0, 2);
- return ByteBuffer.wrap(b).getShort();
- }
-}
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/RelationSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/RelationSpans.java
index f026994..487f841 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/RelationSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/RelationSpans.java
@@ -1,6 +1,7 @@
package de.ids_mannheim.korap.query.spans;
import java.io.IOException;
+import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -12,7 +13,6 @@
import org.apache.lucene.search.spans.Spans;
import org.apache.lucene.search.spans.TermSpans;
import org.apache.lucene.util.Bits;
-import org.apache.lucene.util.BytesRef;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -110,39 +110,39 @@
private void readPayload(CandidateRelationSpan cs) {
List<byte[]> payload = (List<byte[]>) cs.getPayloads();
int length = payload.get(0).length;
- BytesRef payloadBytesRef = new BytesRef(payload.get(0));
+ ByteBuffer bb = ByteBuffer.allocate(length);
+ bb.put(payload.get(0));
- int i;
-
+ int i;
switch (length) {
- case 10: // Token to token
- i = PayloadReader.readInteger(payloadBytesRef,0);
+ case 10: // Token to token
+ i = bb.getInt(0);
cs.setRightStart(i-1);
cs.setRightEnd(i);
break;
case 14: // Token to span
- cs.setRightStart(PayloadReader.readInteger(payloadBytesRef,0));
- cs.setRightEnd(PayloadReader.readInteger(payloadBytesRef,4));
+ cs.setRightStart(bb.getInt(0));
+ cs.setRightEnd(bb.getInt(4));
break;
case 15: // Span to token
- cs.setEnd(PayloadReader.readInteger(payloadBytesRef,0));
- i = PayloadReader.readInteger(payloadBytesRef,5);
+ cs.setEnd(bb.getInt(0));
+ i = bb.getInt(5);
cs.setRightStart(i-1);
cs.setRightEnd(i);
break;
case 18: // Span to span
- cs.setEnd(PayloadReader.readInteger(payloadBytesRef,0));
- cs.setRightStart(PayloadReader.readInteger(payloadBytesRef,4));
- cs.setRightEnd(PayloadReader.readInteger(payloadBytesRef,8));
+ cs.setEnd(bb.getInt(0));
+ cs.setRightStart(bb.getInt(4));
+ cs.setRightEnd(bb.getInt(8));
break;
}
- cs.setRightId(PayloadReader.readShort(payloadBytesRef, length-2)); //right id
- cs.setLeftId(PayloadReader.readShort(payloadBytesRef, length-4)); //left id
- cs.setSpanId(PayloadReader.readShort(payloadBytesRef, length-6)); //relation id
+ cs.setRightId(bb.getShort(length-2)); //right id
+ cs.setLeftId(bb.getShort(length-4)); //left id
+ cs.setSpanId(bb.getShort(length-6)); //relation id
// Payload is cleared.
}
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/SpansWithAttribute.java b/src/main/java/de/ids_mannheim/korap/query/spans/SpansWithAttribute.java
index 9287a4d..40b8d40 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/SpansWithAttribute.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/SpansWithAttribute.java
@@ -33,9 +33,6 @@
protected Logger logger = LoggerFactory.getLogger(SpansWithAttribute.class);
- // This advices the java compiler to ignore all loggings
- public static final boolean DEBUG = false;
-
public SpansWithAttribute(SpanWithAttributeQuery spanWithAttributeQuery,
SpansWithId withIdSpans,
AtomicReaderContext context, Bits acceptDocs,
@@ -115,8 +112,7 @@
for (AttributeSpans attribute: attributeList){
if (withAttributeSpans.getSpanId() != attribute.getSpanId()){
- if (DEBUG)
- logger.info("attribute ref doesn't match");
+// logger.info("attribute ref doesn't match");
if (withAttributeSpans.getSpanId() < attribute.getSpanId())
hasMoreSpans = attribute.next();
else {
@@ -137,8 +133,7 @@
if (!notAttribute.isFinish() &&
withAttributeSpans.start() == notAttribute.start() &&
withAttributeSpans.getSpanId() == notAttribute.getSpanId()){
- if (DEBUG)
- logger.info("not attribute ref exists");
+// logger.info("not attribute ref exists");
hasMoreSpans = withAttributeSpans.next();
return false;
}
@@ -154,17 +149,14 @@
while (hasMoreSpans){
if (withAttributeSpans.getSpanId() < 1){ // the element does not have an attribute
- withAttributeSpans.hasSpanId = true; // dummy setting enabling reading elementRef
hasMoreSpans = withAttributeSpans.next();
- if (DEBUG)
- logger.info("skip");
+// logger.info("skip");
continue;
}
if (checkAttributeListPosition() &&
checkNotAttributeListPosition()){
- if (DEBUG)
- logger.info("element is found: "+ withAttributeSpans.start());
+// logger.info("element is found: "+ withAttributeSpans.start());
return true;
}
}
@@ -181,8 +173,7 @@
for (AttributeSpans a : notAttributeList){
// advance the doc# of not AttributeSpans
- if (DEBUG)
- logger.info("a "+a.start());
+ // logger.info("a "+a.start());
while (!a.isFinish() && a.doc() <= withAttributeSpans.doc()){
if (a.doc() == withAttributeSpans.doc() &&
@@ -206,8 +197,7 @@
for (AttributeSpans a : attributeList){
if(!ensureSamePosition(withAttributeSpans, a)) return false;
- if (DEBUG)
- logger.info("pos:" + withAttributeSpans.start());
+ // logger.info("pos:" + withAttributeSpans.start());
if (isFirst){
isFirst = false;
currentPosition = withAttributeSpans.start();
@@ -218,8 +208,7 @@
}
}
- if (DEBUG)
- logger.info("same pos: "+isSame+ ", pos "+withAttributeSpans.start());
+ // logger.info("same pos: "+isSame+ ", pos "+withAttributeSpans.start());
return isSame;
}
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/TermSpansWithId.java b/src/main/java/de/ids_mannheim/korap/query/spans/TermSpansWithId.java
index 2cf0c5b..7d29adc 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/TermSpansWithId.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/TermSpansWithId.java
@@ -1,6 +1,7 @@
package de.ids_mannheim.korap.query.spans;
import java.io.IOException;
+import java.nio.ByteBuffer;
import java.util.List;
import java.util.Map;
@@ -51,8 +52,9 @@
private void readPayload() throws IOException{
List<byte[]> payload = (List<byte[]>) firstSpans.getPayload();
- BytesRef payloadBytesRef = new BytesRef(payload.get(0));
- setSpanId(PayloadReader.readShort(payloadBytesRef, 0)); //term id
+ ByteBuffer bb = ByteBuffer.allocate(payload.get(0).length);
+ bb.put(payload.get(0));
+ setSpanId(bb.getShort(0)); //term id
}