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
Original file line number Diff line number Diff line change
Expand Up @@ -382,23 +382,23 @@ public Clusters getClusters() {
@Override
public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params) {
assert hasReferences();
return Iterators.concat(
ChunkedToXContentHelper.startObject(),
this.innerToXContentChunked(params),
ChunkedToXContentHelper.endObject()
);
return getToXContentIterator(true, params);
}

public Iterator<? extends ToXContent> innerToXContentChunked(ToXContent.Params params) {
return getToXContentIterator(false, params);
}

private Iterator<ToXContent> getToXContentIterator(boolean wrapInObject, ToXContent.Params params) {
return Iterators.concat(
wrapInObject ? ChunkedToXContentHelper.startObject() : Collections.emptyIterator(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very lazy solution admittedly here and for the end-object but it doesn't matter as the cost comes from the hits iterator anyway.

ChunkedToXContentHelper.chunk(SearchResponse.this::headerToXContent),
Iterators.single(clusters),
Iterators.concat(
hits.toXContentChunked(params),
aggregations == null ? Collections.emptyIterator() : ChunkedToXContentHelper.chunk(aggregations),
suggest == null ? Collections.emptyIterator() : ChunkedToXContentHelper.chunk(suggest),
profileResults == null ? Collections.emptyIterator() : ChunkedToXContentHelper.chunk(profileResults)
)
hits.toXContentChunked(params),
aggregations == null ? Collections.emptyIterator() : ChunkedToXContentHelper.chunk(aggregations),
suggest == null ? Collections.emptyIterator() : ChunkedToXContentHelper.chunk(suggest),
profileResults == null ? Collections.emptyIterator() : ChunkedToXContentHelper.chunk(profileResults),
wrapInObject ? ChunkedToXContentHelper.endObject() : Collections.emptyIterator()
);
}

Expand Down