Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 26 additions & 51 deletions server/src/main/java/org/opensearch/common/lucene/Lucene.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,63 +357,38 @@
public static FieldDoc readFieldDoc(StreamInput in) throws IOException {
Comparable[] cFields = new Comparable[in.readVInt()];
for (int j = 0; j < cFields.length; j++) {
byte type = in.readByte();
if (type == 0) {
cFields[j] = null;
} else if (type == 1) {
cFields[j] = in.readString();
} else if (type == 2) {
cFields[j] = in.readInt();
} else if (type == 3) {
cFields[j] = in.readLong();
} else if (type == 4) {
cFields[j] = in.readFloat();
} else if (type == 5) {
cFields[j] = in.readDouble();
} else if (type == 6) {
cFields[j] = in.readByte();
} else if (type == 7) {
cFields[j] = in.readShort();
} else if (type == 8) {
cFields[j] = in.readBoolean();
} else if (type == 9) {
cFields[j] = in.readBytesRef();
} else if (type == 10) {
cFields[j] = new BigInteger(in.readString());
} else {
throw new IOException("Can't match type [" + type + "]");
}
cFields[j] = readTypedValue(in);
}
return new FieldDoc(in.readVInt(), in.readFloat(), cFields);
}

public static Comparable readSortValue(StreamInput in) throws IOException {
return readTypedValue(in);
}

/**
* Reads a typed value from the stream based on a type byte prefix.
*
* @param in the input stream
* @return the deserialized Comparable value
* @throws IOException if reading fails or type is unknown
*/
private static Comparable readTypedValue(StreamInput in) throws IOException {
byte type = in.readByte();
if (type == 0) {
return null;
} else if (type == 1) {
return in.readString();
} else if (type == 2) {
return in.readInt();
} else if (type == 3) {
return in.readLong();
} else if (type == 4) {
return in.readFloat();
} else if (type == 5) {
return in.readDouble();
} else if (type == 6) {
return in.readByte();
} else if (type == 7) {
return in.readShort();
} else if (type == 8) {
return in.readBoolean();
} else if (type == 9) {
return in.readBytesRef();
} else if (type == 10) {
return new BigInteger(in.readString());
} else {
throw new IOException("Can't match type [" + type + "]");
}
return switch (type) {
case 0 -> null;
case 1 -> in.readString();
case 2 -> in.readInt();
case 3 -> in.readLong();
case 4 -> in.readFloat();
case 5 -> in.readDouble();
case 6 -> in.readByte();
case 7 -> in.readShort();
case 8 -> in.readBoolean();
case 9 -> in.readBytesRef();
case 10 -> new BigInteger(in.readString());
default -> throw new IOException("Can't match type [" + type + "]");

Check warning on line 390 in server/src/main/java/org/opensearch/common/lucene/Lucene.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/common/lucene/Lucene.java#L389-L390

Added lines #L389 - L390 were not covered by tests
};
}

public static ScoreDoc readScoreDoc(StreamInput in) throws IOException {
Expand Down
Loading