Skip to content

Commit

Permalink
Handle null totHits
Browse files Browse the repository at this point in the history
Signed-off-by: Finn Carroll <[email protected]>
  • Loading branch information
finnegancarroll committed Aug 28, 2024
1 parent 7f0b06d commit a1a6b94
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ SearchHitsProto toProto() {
builder.addHits(new SearchHitProtobuf(hit).toProto());
}

TotalHits totHits = totalHits;
TotalHitsProto.Builder totHitsBuilder = TotalHitsProto.newBuilder().setRelation(totHits.relation.ordinal()).setValue(totHits.value);
builder.setTotalHits(totHitsBuilder);
if (totalHits != null) {
TotalHitsProto.Builder totHitsBuilder = TotalHitsProto.newBuilder().setRelation(totalHits.relation.ordinal()).setValue(totalHits.value);
builder.setTotalHits(totHitsBuilder);
}

try (BytesStreamOutput sortOut = new BytesStreamOutput()) {
sortOut.writeOptionalArray(Lucene::writeSortField, sortFields);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,6 @@ public static SearchHitsProtobuf createTestItem(boolean withOptionalInnerHits, b
return createTestItem(randomFrom(XContentType.values()), withOptionalInnerHits, withShardTarget);
}

private static SearchHit[] createSearchHitArray(
int size,
final MediaType mediaType,
boolean withOptionalInnerHits,
boolean transportSerialization
) {
SearchHit[] hits = new SearchHit[size];
for (int i = 0; i < hits.length; i++) {
hits[i] = SearchHitTests.createTestItem(mediaType, withOptionalInnerHits, transportSerialization);
}
return hits;
}

private static TotalHits randomTotalHits(TotalHits.Relation relation) {
long totalHits = TestUtil.nextLong(random(), 0, Long.MAX_VALUE);
return new TotalHits(totalHits, relation);
}

public static SearchHitsProtobuf createTestItem(final MediaType mediaType, boolean withOptionalInnerHits, boolean transportSerialization) {
return createTestItem(mediaType, withOptionalInnerHits, transportSerialization, randomFrom(TotalHits.Relation.values()));
}
Expand All @@ -118,6 +100,24 @@ private static SearchHitsProtobuf createTestItem(
return new SearchHitsProtobuf(new SearchHits(hits, totalHits, maxScore, sortFields, collapseField, collapseValues));
}

private static SearchHit[] createSearchHitArray(
int size,
final MediaType mediaType,
boolean withOptionalInnerHits,
boolean transportSerialization
) {
SearchHit[] hits = new SearchHit[size];
for (int i = 0; i < hits.length; i++) {
hits[i] = SearchHitTests.createTestItem(mediaType, withOptionalInnerHits, transportSerialization);
}
return hits;
}

private static TotalHits randomTotalHits(TotalHits.Relation relation) {
long totalHits = TestUtil.nextLong(random(), 0, Long.MAX_VALUE);
return new TotalHits(totalHits, relation);
}

private static SortField[] createSortFields(int size) {
SortField[] sortFields = new SortField[size];
for (int i = 0; i < sortFields.length; i++) {
Expand Down

0 comments on commit a1a6b94

Please sign in to comment.