Skip to content

Commit

Permalink
Update version checks
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Ross <[email protected]>
  • Loading branch information
andrross committed Feb 22, 2024
1 parent ccbd26b commit 0aae97b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
34 changes: 32 additions & 2 deletions server/src/main/java/org/opensearch/search/SearchHit.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public SearchHit(StreamInput in) throws IOException {
sortValues = new SearchSortValues(in);

size = in.readVInt();
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
if (in.getVersion().onOrAfter(Version.V_2_13_0)) {
if (size > 0) {
Map<String, Float> tempMap = in.readMap(StreamInput::readString, StreamInput::readFloat);
matchedQueries = tempMap.entrySet()
Expand Down Expand Up @@ -249,6 +249,36 @@ public SearchHit(StreamInput in) throws IOException {
}
}

private Map<String, DocumentField> readFields(StreamInput in) throws IOException {
Map<String, DocumentField> fields;
int size = in.readVInt();
if (size == 0) {
fields = emptyMap();
} else if (size == 1) {
DocumentField hitField = new DocumentField(in);
fields = singletonMap(hitField.getName(), hitField);
} else {
fields = new HashMap<>(size);
for (int i = 0; i < size; i++) {
DocumentField field = new DocumentField(in);
fields.put(field.getName(), field);
}
fields = unmodifiableMap(fields);
}
return fields;
}

private void writeFields(StreamOutput out, Map<String, DocumentField> fields) throws IOException {
if (fields == null) {
out.writeVInt(0);
} else {
out.writeVInt(fields.size());
for (DocumentField field : fields.values()) {
field.writeTo(out);
}
}
}

private static final Text SINGLE_MAPPING_TYPE = new Text(MapperService.SINGLE_MAPPING_NAME);

@Override
Expand Down Expand Up @@ -286,7 +316,7 @@ public void writeTo(StreamOutput out) throws IOException {
sortValues.writeTo(out);

out.writeVInt(matchedQueries.size());
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
if (out.getVersion().onOrAfter(Version.V_2_13_0)) {
if (!matchedQueries.isEmpty()) {
out.writeMap(matchedQueries, StreamOutput::writeString, StreamOutput::writeFloat);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public SearchSourceBuilder(StreamInput in) throws IOException {
searchPipelineSource = in.readMap();
}
}
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
if (in.getVersion().onOrAfter(Version.V_2_13_0)) {
includeNamedQueriesScore = in.readOptionalBoolean();
}
}
Expand Down Expand Up @@ -364,7 +364,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeMap(searchPipelineSource);
}
}
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
if (out.getVersion().onOrAfter(Version.V_2_13_0)) {
out.writeOptionalBoolean(includeNamedQueriesScore);
}
}
Expand Down

0 comments on commit 0aae97b

Please sign in to comment.