Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,34 @@ private static void processMetadataFields(SearchHit hit, org.opensearch.protobuf
}
}

/**
* Maps OpenSearch MediaType to protobuf SourceContentType enum.
*
* @param mediaType The MediaType to map
* @return The corresponding SourceContentType enum value
*/
private static org.opensearch.protobufs.SourceContentType mapMediaTypeToProtoEnum(
org.opensearch.core.xcontent.MediaType mediaType
) {
String format = mediaType.format();
if (format == null) {
return org.opensearch.protobufs.SourceContentType.SOURCE_CONTENT_TYPE_UNSPECIFIED;
}

switch (format.toLowerCase()) {
case "json":
return org.opensearch.protobufs.SourceContentType.SOURCE_CONTENT_TYPE_JSON;
case "smile":
return org.opensearch.protobufs.SourceContentType.SOURCE_CONTENT_TYPE_SMILE;
case "cbor":
return org.opensearch.protobufs.SourceContentType.SOURCE_CONTENT_TYPE_CBOR;
case "yaml":
return org.opensearch.protobufs.SourceContentType.SOURCE_CONTENT_TYPE_YAML;
default:
return org.opensearch.protobufs.SourceContentType.SOURCE_CONTENT_TYPE_UNSPECIFIED;
}
}

/**
* Helper method to process source information.
*
Expand All @@ -209,6 +237,13 @@ private static void processSource(SearchHit hit, org.opensearch.protobufs.HitsMe
} else {
hitBuilder.setXSource(ByteString.copyFrom(bytesRef.bytes, bytesRef.offset, bytesRef.length));
}

// Detect and set the source content type
org.opensearch.core.xcontent.MediaType mediaType = org.opensearch.core.xcontent.MediaTypeRegistry.xContentType(sourceRef);
if (mediaType != null) {
org.opensearch.protobufs.SourceContentType sourceContentType = mapMediaTypeToProtoEnum(mediaType);
hitBuilder.setXSourceContentType(sourceContentType);
}
}
}

Expand Down
Loading