2021-10-13 00:23:56 +02:00
|
|
|
package it.cavallium.dbengine.lucene;
|
|
|
|
|
2022-04-06 02:41:32 +02:00
|
|
|
import io.netty5.buffer.api.Buffer;
|
2021-10-13 00:23:56 +02:00
|
|
|
import java.util.function.Function;
|
|
|
|
|
2022-04-06 02:41:32 +02:00
|
|
|
public class LLScoreDocCodec implements HugePqCodec<LLScoreDoc> {
|
2021-10-13 00:23:56 +02:00
|
|
|
|
|
|
|
@Override
|
2022-04-06 02:41:32 +02:00
|
|
|
public Buffer serialize(Function<Integer, Buffer> allocator, LLScoreDoc data) {
|
2021-10-13 00:23:56 +02:00
|
|
|
var buf = allocator.apply(Float.BYTES + Integer.BYTES + Integer.BYTES);
|
2022-04-06 02:41:32 +02:00
|
|
|
buf.writerOffset(Float.BYTES + Integer.BYTES + Integer.BYTES);
|
2021-10-13 00:23:56 +02:00
|
|
|
setScore(buf, data.score());
|
|
|
|
setDoc(buf, data.doc());
|
|
|
|
setShardIndex(buf, data.shardIndex());
|
2022-04-06 02:41:32 +02:00
|
|
|
return buf;
|
2021-10-13 00:23:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-04-06 02:41:32 +02:00
|
|
|
public LLScoreDoc deserialize(Buffer buf) {
|
2021-10-13 00:23:56 +02:00
|
|
|
return new LLScoreDoc(getDoc(buf), getScore(buf), getShardIndex(buf));
|
|
|
|
}
|
|
|
|
|
2022-04-06 02:41:32 +02:00
|
|
|
private static float getScore(Buffer hit) {
|
|
|
|
return HugePqCodec.getLexFloat(hit, 0, false);
|
2021-10-13 00:23:56 +02:00
|
|
|
}
|
|
|
|
|
2022-04-06 02:41:32 +02:00
|
|
|
private static int getDoc(Buffer hit) {
|
|
|
|
return HugePqCodec.getLexInt(hit, Float.BYTES, true);
|
2021-10-13 00:23:56 +02:00
|
|
|
}
|
|
|
|
|
2022-04-06 02:41:32 +02:00
|
|
|
private static int getShardIndex(Buffer hit) {
|
|
|
|
return HugePqCodec.getLexInt(hit, Float.BYTES + Integer.BYTES, false);
|
2021-10-13 00:23:56 +02:00
|
|
|
}
|
|
|
|
|
2022-04-06 02:41:32 +02:00
|
|
|
private static void setScore(Buffer hit, float score) {
|
|
|
|
HugePqCodec.setLexFloat(hit, 0, false, score);
|
2021-10-13 00:23:56 +02:00
|
|
|
}
|
|
|
|
|
2022-04-06 02:41:32 +02:00
|
|
|
private static void setDoc(Buffer hit, int doc) {
|
|
|
|
HugePqCodec.setLexInt(hit, Float.BYTES, true, doc);
|
2021-10-13 00:23:56 +02:00
|
|
|
}
|
|
|
|
|
2022-04-06 02:41:32 +02:00
|
|
|
private static void setShardIndex(Buffer hit, int shardIndex) {
|
|
|
|
HugePqCodec.setLexInt(hit, Float.BYTES + Integer.BYTES, false, shardIndex);
|
2021-10-13 00:23:56 +02:00
|
|
|
}
|
|
|
|
|
2022-04-06 02:41:32 +02:00
|
|
|
@Override
|
|
|
|
public LLScoreDoc clone(LLScoreDoc obj) {
|
|
|
|
return new LLScoreDoc(obj.doc(), obj.score(), obj.shardIndex());
|
2021-10-13 00:23:56 +02:00
|
|
|
}
|
|
|
|
}
|