Skip to content

Commit

Permalink
resolve early feedback from @msfroh
Browse files Browse the repository at this point in the history
  • Loading branch information
noCharger committed Apr 14, 2023
1 parent 19a3004 commit c5c2e39
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ public SearchRequest processRequest(SearchRequest request) throws Exception {
searchScript = precompiledSearchScript;
}
// convert the search request to a map
Map<String, Object> cxt = Map.of("source", request.source().toMap());
Map<String, Object> ctx = Map.of("source", request.source().toMap());
// execute the script with the search request in context
searchScript.execute(cxt);
CollectionUtils.ensureNoSelfReferences(cxt, "search script");
// assert cxt has at least one key and it contains source key
if (cxt.isEmpty() || cxt.get("source") == null) {
searchScript.execute(ctx);
CollectionUtils.ensureNoSelfReferences(ctx, "search script");
// assert ctx has at least one key and it contains source key
if (ctx.isEmpty() || ctx.get("source") == null) {
throw new IllegalArgumentException("script must have at least one key");
}

Object obj = cxt.get("source");
Object obj = ctx.get("source");
if (obj instanceof Map<?, ?>) {
Map<?, ?> rawMap = (Map<?, ?>) obj;
Map<String, Object> resultMap = new LinkedHashMap<>();
Expand Down
4 changes: 2 additions & 2 deletions server/src/main/java/org/opensearch/script/SearchScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
public abstract class SearchScript {

This comment has been minimized.

Copy link
@msfroh

msfroh Apr 14, 2023

We'll probably want to rename this to SearchPipelineScript (all the other search pipeline-related classes have SearchPipeline as their prefix).


public static final String[] PARAMETERS = { "cxt" };
public static final String[] PARAMETERS = { "ctx" };

/** The context used to compile {@link SearchScript} factories. */
public static final ScriptContext<Factory> CONTEXT = new ScriptContext<>(
Expand All @@ -42,7 +42,7 @@ public Map<String, Object> getParams() {
return params;
}

public abstract void execute(Map<String, Object> cxt);
public abstract void execute(Map<String, Object> ctx);

/**
* Factory for ingest script
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1560,9 +1560,7 @@ public Map<String, Object> toMap() {
}

if (queryBuilder instanceof QueryStringQueryBuilder) {
String queryString = ((QueryStringQueryBuilder) queryBuilder).queryString();
// deep copy of original query string
attributes.put("query", queryString.substring(0));
attributes.put("query", ((QueryStringQueryBuilder) queryBuilder).queryString());
}

attributes.put("postQuery", postQueryBuilder);
Expand Down

0 comments on commit c5c2e39

Please sign in to comment.