Skip to content
Merged
Show file tree
Hide file tree
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 @@ -129,6 +129,69 @@ public SearchResponse(StreamInput in) throws IOException {
pointInTimeId = in.readOptionalString();
}

/**
* Creates a new SearchResponse that is not tied to a point in time and has no phase timings.
*
* @param internalResponse the response sections
* @param scrollId the scroll identifier, or null
* @param totalShards the number of shards the request went to
* @param successfulShards the number of shards that answered
* @param skippedShards the number of shards that were skipped
* @param tookInMillis how long the request took, in milliseconds
* @param shardFailures the shard failures
* @param clusters the clusters the request went to
*/
public SearchResponse(
SearchResponseSections internalResponse,
String scrollId,
int totalShards,
int successfulShards,
int skippedShards,
long tookInMillis,
ShardSearchFailure[] shardFailures,
Clusters clusters
) {
this(internalResponse, scrollId, totalShards, successfulShards, skippedShards, tookInMillis, null, shardFailures, clusters, null);
}

/**
* Creates a new SearchResponse with no phase timings.
*
* @param internalResponse the response sections
* @param scrollId the scroll identifier, or null
* @param totalShards the number of shards the request went to
* @param successfulShards the number of shards that answered
* @param skippedShards the number of shards that were skipped
* @param tookInMillis how long the request took, in milliseconds
* @param shardFailures the shard failures
* @param clusters the clusters the request went to
* @param pointInTimeId the point-in-time identifier, or null
*/
public SearchResponse(
SearchResponseSections internalResponse,
String scrollId,
int totalShards,
int successfulShards,
int skippedShards,
long tookInMillis,
ShardSearchFailure[] shardFailures,
Clusters clusters,
String pointInTimeId
) {
this(
internalResponse,
scrollId,
totalShards,
successfulShards,
skippedShards,
tookInMillis,
null,
shardFailures,
clusters,
pointInTimeId
);
}

public SearchResponse(
SearchResponseSections internalResponse,
String scrollId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ public class ShardSearchFailure extends ShardOperationFailedException {
cause = in.readException();
}

/**
* Creates a new ShardSearchFailure for a failure that is not tied to a shard.
*
* @param e the exception that caused the failure
*/
public ShardSearchFailure(Exception e) {
this(e, null);
}

public ShardSearchFailure(Exception e, @Nullable SearchShardTarget shardTarget) {
this(e, ExceptionsHelper.unwrapCause(e), shardTarget);
}
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/codelibs/fesen/opensearch/search/SearchHits.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ public final class SearchHits implements Writeable, ToXContentFragment, Iterable
@Nullable
private final Object[] collapseValues;

/**
* Returns hits that carry nothing, with a total hit count of zero.
*
* @return the empty hits
*/
public static SearchHits empty() {
return empty(true);
}

/**
* Returns hits that carry nothing.
*
* @param withTotalHits whether to report a total hit count of zero rather than none at all
* @return the empty hits
*/
public static SearchHits empty(boolean withTotalHits) {
return new SearchHits(EMPTY, withTotalHits ? new TotalHits(0, TotalHits.Relation.EQUAL_TO) : null, 0);
}

public SearchHits(SearchHit[] hits, @Nullable TotalHits totalHits, float maxScore) {
this(hits, totalHits, maxScore, null, null, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,93 @@
@PublicApi(since = "1.0.0")
public class InternalSearchResponse extends SearchResponseSections implements Writeable, ToXContentFragment {

/**
* Returns a response that carries no hits.
*
* @return the empty response
*/
public static InternalSearchResponse empty() {
return empty(true);
}

/**
* Returns a response that carries no hits.
*
* @param withTotalHits whether to report a total hit count of zero rather than none at all
* @return the empty response
*/
public static InternalSearchResponse empty(boolean withTotalHits) {
return new InternalSearchResponse(SearchHits.empty(withTotalHits), null, null, null, false, null, 1);
}

/**
* Creates a new InternalSearchResponse with no search extensions and no processor results.
*
* @param hits the hits
* @param aggregations the aggregations
* @param suggest the suggestions
* @param profileResults the profile results
* @param timedOut whether the query timed out
* @param terminatedEarly whether collection stopped early
* @param numReducePhases the number of reduce phases
*/
public InternalSearchResponse(
SearchHits hits,
InternalAggregations aggregations,
Suggest suggest,
SearchProfileShardResults profileResults,
boolean timedOut,
Boolean terminatedEarly,
int numReducePhases
) {
this(
hits,
aggregations,
suggest,
profileResults,
timedOut,
terminatedEarly,
numReducePhases,
Collections.emptyList(),
Collections.emptyList()
);
}

/**
* Creates a new InternalSearchResponse with no processor results.
*
* @param hits the hits
* @param aggregations the aggregations
* @param suggest the suggestions
* @param profileResults the profile results
* @param timedOut whether the query timed out
* @param terminatedEarly whether collection stopped early
* @param numReducePhases the number of reduce phases
* @param searchExtBuilderList the search extensions
*/
public InternalSearchResponse(
SearchHits hits,
InternalAggregations aggregations,
Suggest suggest,
SearchProfileShardResults profileResults,
boolean timedOut,
Boolean terminatedEarly,
int numReducePhases,
List<SearchExtBuilder> searchExtBuilderList
) {
this(
hits,
aggregations,
suggest,
profileResults,
timedOut,
terminatedEarly,
numReducePhases,
searchExtBuilderList,
Collections.emptyList()
);
}

public InternalSearchResponse(
SearchHits hits,
InternalAggregations aggregations,
Expand Down
Loading