-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support ML Inference Search Processor Writing to Search Extension (#3061
- Loading branch information
Showing
4 changed files
with
714 additions
and
19 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
plugin/src/main/java/org/opensearch/ml/processor/MLInferenceSearchResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.ml.processor; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
import org.opensearch.action.search.SearchResponse; | ||
import org.opensearch.action.search.SearchResponseSections; | ||
import org.opensearch.action.search.ShardSearchFailure; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
|
||
public class MLInferenceSearchResponse extends SearchResponse { | ||
private static final String EXT_SECTION_NAME = "ext"; | ||
|
||
private Map<String, Object> params; | ||
|
||
public MLInferenceSearchResponse( | ||
Map<String, Object> params, | ||
SearchResponseSections internalResponse, | ||
String scrollId, | ||
int totalShards, | ||
int successfulShards, | ||
int skippedShards, | ||
long tookInMillis, | ||
ShardSearchFailure[] shardFailures, | ||
Clusters clusters | ||
) { | ||
super(internalResponse, scrollId, totalShards, successfulShards, skippedShards, tookInMillis, shardFailures, clusters); | ||
this.params = params; | ||
} | ||
|
||
public void setParams(Map<String, Object> params) { | ||
this.params = params; | ||
} | ||
|
||
public Map<String, Object> getParams() { | ||
return this.params; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
innerToXContent(builder, params); | ||
|
||
if (this.params != null) { | ||
builder.startObject(EXT_SECTION_NAME); | ||
builder.field(MLInferenceSearchResponseProcessor.TYPE, this.params); | ||
|
||
builder.endObject(); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.