Skip to content

Commit

Permalink
Spotless apply
Browse files Browse the repository at this point in the history
Signed-off-by: Finn Carroll <carrofin@amazon.com>
  • Loading branch information
finnegancarroll committed Aug 27, 2024
1 parent 717da75 commit ebadf6f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 48 deletions.
2 changes: 1 addition & 1 deletion server/src/main/java/org/opensearch/search/SearchHits.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public SearchHits(StreamInput in) throws IOException {
collapseValues = in.readOptionalArray(Lucene::readSortValue, Object[]::new);
}

protected SearchHits () {}
protected SearchHits() {}

@Override
public void writeTo(StreamOutput out) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public void toProtobufStream(StreamOutput out) throws IOException {
toProto().writeTo(out);
}


@Override
public void fromProtobufStream(StreamInput in) throws IOException {
FetchSearchResultProto proto = FetchSearchResultProto.parseFrom(in);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import org.opensearch.search.SearchShardTarget;
import org.opensearch.search.SearchSortValues;
import org.opensearch.search.fetch.subphase.highlight.HighlightField;
import org.opensearch.serde.proto.SearchHitsTransportProto.SearchHitProto;
import org.opensearch.serde.proto.SearchHitsTransportProto.NestedIdentityProto;
import org.opensearch.serde.proto.SearchHitsTransportProto.SearchHitProto;

import java.io.IOException;
import java.util.HashMap;
Expand Down Expand Up @@ -197,17 +197,11 @@ SearchHitProto toProto() {
builder.setExplanation(explanationToProto(explanation));
builder.setSortValues(searchSortValuesToProto(sortValues));

documentFields.forEach((key, value) ->
builder.putDocumentFields(key, documentFieldToProto(value))
);
documentFields.forEach((key, value) -> builder.putDocumentFields(key, documentFieldToProto(value)));

metaFields.forEach((key, value) ->
builder.putMetaFields(key, documentFieldToProto(value))
);
metaFields.forEach((key, value) -> builder.putMetaFields(key, documentFieldToProto(value)));

highlightFields.forEach((key, value) ->
builder.putHighlightFields(key, highlightFieldToProto(value))
);
highlightFields.forEach((key, value) -> builder.putHighlightFields(key, highlightFieldToProto(value)));

matchedQueries.forEach(builder::putMatchedQueries);

Expand All @@ -216,9 +210,7 @@ SearchHitProto toProto() {
builder.setShard(searchShardTargetToProto(shard));
}

innerHits.forEach((key, value) ->
builder.putInnerHits(key, new SearchHitsSerDe(value, strategy).toProto())
);
innerHits.forEach((key, value) -> builder.putInnerHits(key, new SearchHitsSerDe(value, strategy).toProto()));

return builder.build();
}
Expand All @@ -237,24 +229,16 @@ void fromProto(SearchHitProto proto) throws SerDe.SerializationException {
matchedQueries = proto.getMatchedQueriesMap();

documentFields = new HashMap<>();
proto.getDocumentFieldsMap().forEach((key, value) ->
documentFields.put(key, documentFieldFromProto(value))
);
proto.getDocumentFieldsMap().forEach((key, value) -> documentFields.put(key, documentFieldFromProto(value)));

metaFields = new HashMap<>();
proto.getMetaFieldsMap().forEach((key, value) ->
metaFields.put(key, documentFieldFromProto(value))
);
proto.getMetaFieldsMap().forEach((key, value) -> metaFields.put(key, documentFieldFromProto(value)));

highlightFields = new HashMap<>();
proto.getHighlightFieldsMap().forEach((key, value) ->
highlightFields.put(key, highlightFieldFromProto(value))
);
proto.getHighlightFieldsMap().forEach((key, value) -> highlightFields.put(key, highlightFieldFromProto(value)));

innerHits = new HashMap<>();
proto.getInnerHitsMap().forEach((key, value) ->
innerHits.put(key, new SearchHitsSerDe(value))
);
proto.getInnerHitsMap().forEach((key, value) -> innerHits.put(key, new SearchHitsSerDe(value)));

shard = searchShardTargetFromProto(proto.getShard());
index = shard.getIndex();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,31 +111,27 @@ public void fromNativeStream(StreamInput in) throws IOException {
}

SearchHitsProto toProto() {
SearchHitsProto.Builder builder = SearchHitsProto.newBuilder()
.setMaxScore(maxScore)
.setCollapseField(collapseField);
SearchHitsProto.Builder builder = SearchHitsProto.newBuilder().setMaxScore(maxScore).setCollapseField(collapseField);

for (SearchHit hit : hits) {
builder.addHits(new SearchHitSerDe(hit, strategy).toProto());
}

TotalHits totHits = totalHits;
TotalHitsProto.Builder totHitsBuilder = TotalHitsProto.newBuilder()
.setRelation(totHits.relation.ordinal())
.setValue(totHits.value);
TotalHitsProto.Builder totHitsBuilder = TotalHitsProto.newBuilder().setRelation(totHits.relation.ordinal()).setValue(totHits.value);
builder.setTotalHits(totHitsBuilder);

try (BytesStreamOutput sortOut = new BytesStreamOutput()) {
sortOut.writeOptionalArray(Lucene::writeSortField, sortFields);
builder.setSortFields(ByteString.copyFrom(sortOut.bytes().toBytesRef().bytes));
} catch (IOException e){
} catch (IOException e) {
throw new SerDe.SerializationException("Failed to serialize SearchHits to proto", e);
}

try (BytesStreamOutput collapseOut = new BytesStreamOutput()) {
collapseOut.writeOptionalArray(Lucene::writeSortValue, collapseValues);
builder.setCollapseValues(ByteString.copyFrom(collapseOut.bytes().toBytesRef().bytes));
} catch (IOException e){
} catch (IOException e) {
throw new SerDe.SerializationException("Failed to serialize SearchHits to proto", e);
}

Expand Down Expand Up @@ -167,7 +163,7 @@ void fromProto(SearchHitsProto proto) throws SerDe.SerializationException {
}

hits = new SearchHit[proto.getHitsCount()];
for(int i = 0; i < hits.length; i++) {
for (int i = 0; i < hits.length; i++) {
try {
hits[i] = new SearchHitSerDe(proto.getHits(i));
} catch (IOException e) {
Expand Down
23 changes: 11 additions & 12 deletions server/src/main/java/org/opensearch/transport/serde/SerDe.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
import org.opensearch.search.SearchSortValues;
import org.opensearch.search.fetch.subphase.highlight.HighlightField;
import org.opensearch.serde.proto.SearchHitsTransportProto.DocumentFieldProto;
import org.opensearch.serde.proto.SearchHitsTransportProto.ExplanationProto;
import org.opensearch.serde.proto.SearchHitsTransportProto.HighlightFieldProto;
import org.opensearch.serde.proto.SearchHitsTransportProto.SearchSortValuesProto;
import org.opensearch.serde.proto.SearchHitsTransportProto.IndexProto;
import org.opensearch.serde.proto.SearchHitsTransportProto.SearchShardTargetProto;
import org.opensearch.serde.proto.SearchHitsTransportProto.ExplanationProto;
import org.opensearch.serde.proto.SearchHitsTransportProto.SearchSortValuesProto;
import org.opensearch.serde.proto.SearchHitsTransportProto.ShardIdProto;
import org.opensearch.serde.proto.SearchHitsTransportProto.IndexProto;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -55,18 +55,21 @@ public static class SerializationException extends RuntimeException {
public SerializationException(String message) {
super(message);
}

public SerializationException(String message, Throwable cause) {
super(message, cause);
}
}

interface nativeSerializer {
void toNativeStream(StreamOutput out) throws IOException;

void fromNativeStream(StreamInput in) throws IOException;
}

interface protobufSerializer {
void toProtobufStream(StreamOutput out) throws IOException;

void fromProtobufStream(StreamInput in) throws IOException;
}

Expand Down Expand Up @@ -108,7 +111,7 @@ static DocumentFieldProto documentFieldToProto(DocumentField field) {
try (BytesStreamOutput docsOut = new BytesStreamOutput()) {
docsOut.writeCollection(field.getValues(), StreamOutput::writeGenericValue);
builder.addValues(ByteString.copyFrom(docsOut.bytes().toBytesRef().bytes));
} catch (IOException e){
} catch (IOException e) {
builder.addValues(ByteString.EMPTY);
}

Expand All @@ -133,8 +136,7 @@ static DocumentField documentFieldFromProto(DocumentFieldProto proto) throws Ser
}

static HighlightFieldProto highlightFieldToProto(HighlightField field) {
HighlightFieldProto.Builder builder = HighlightFieldProto.newBuilder()
.setName(field.getName());
HighlightFieldProto.Builder builder = HighlightFieldProto.newBuilder().setName(field.getName());

for (Text frag : field.getFragments()) {
builder.addFragments(frag.string());
Expand All @@ -161,14 +163,14 @@ static SearchSortValuesProto searchSortValuesToProto(SearchSortValues searchSort
try (BytesStreamOutput formOut = new BytesStreamOutput()) {
formOut.writeArray(Lucene::writeSortValue, searchSortValues.getFormattedSortValues());
builder.addFormattedSortValues(ByteString.copyFrom(formOut.bytes().toBytesRef().bytes));
} catch (IOException e){
} catch (IOException e) {
builder.addFormattedSortValues(ByteString.EMPTY);
}

try (BytesStreamOutput rawOut = new BytesStreamOutput()) {
rawOut.writeArray(Lucene::writeSortValue, searchSortValues.getFormattedSortValues());
builder.addRawSortValues(ByteString.copyFrom(rawOut.bytes().toBytesRef().bytes));
} catch (IOException e){
} catch (IOException e) {
builder.addRawSortValues(ByteString.EMPTY);
}

Expand Down Expand Up @@ -230,10 +232,7 @@ public static ShardId shardIdFromProto(ShardIdProto proto) {
}

static IndexProto indexToProto(Index index) {
return IndexProto.newBuilder()
.setName(index.getName())
.setUuid(index.getUUID())
.build();
return IndexProto.newBuilder().setName(index.getName()).setUuid(index.getUUID()).build();
}

public static Index indexFromProto(IndexProto proto) {
Expand Down

0 comments on commit ebadf6f

Please sign in to comment.