/** * Return the parameters for this script. */ public Map<String, Object> getParams() { this.params.putAll(leafLookup.asMap()); return params; }
public MapScript(Map<String, Object> params, Object state, SearchLookup lookup, LeafReaderContext leafContext) { this.state = state; this.leafLookup = leafContext == null ? null : lookup.getLeafSearchLookup(leafContext); if (leafLookup != null) { params = new HashMap<>(params); // copy params so we aren't modifying input params.putAll(leafLookup.asMap()); // add lookup vars params = new ParameterMap(params, DEPRECATIONS); // wrap with deprecations } this.params = params; }
public ScoreScript(Map<String, Object> params, SearchLookup lookup, LeafReaderContext leafContext) { // null check needed b/c of expression engine subclass if (lookup == null) { assert params == null; assert leafContext == null; this.params = null; this.leafLookup = null; } else { this.leafLookup = lookup.getLeafSearchLookup(leafContext); params = new HashMap<>(params); params.putAll(leafLookup.asMap()); this.params = new ParameterMap(params, DEPRECATIONS); } }
/** * Return the parameters for this script. */ public Map<String, Object> getParams() { this.params.putAll(leafLookup.asMap()); return params; }
/** * Return the parameters for this script. */ public Map<String, Object> getParams() { this.params.putAll(leafLookup.asMap()); return params; }
public FilterScript newInstance(LeafReaderContext context) throws IOException { LeafSearchLookup leafLookup = lookup.getLeafSearchLookup(context); Map<String, Object> ctx = new HashMap<>(leafLookup.asMap()); if (vars != null) { ctx.putAll(vars); } return new FilterScript(ctx, lookup, context) { @Override public boolean execute() { return (boolean) script.apply(ctx); } @Override public void setDocument(int doc) { leafLookup.setDocument(doc); } }; } }
public MapScript(Map<String, Object> params, Object state, SearchLookup lookup, LeafReaderContext leafContext) { this.state = state; this.leafLookup = leafContext == null ? null : lookup.getLeafSearchLookup(leafContext); if (leafLookup != null) { params = new HashMap<>(params); // copy params so we aren't modifying input params.putAll(leafLookup.asMap()); // add lookup vars params = new ParameterMap(params, DEPRECATIONS); // wrap with deprecations } this.params = params; }
public ScoreScript(Map<String, Object> params, SearchLookup lookup, LeafReaderContext leafContext) { // null check needed b/c of expression engine subclass if (lookup == null) { assert params == null; assert leafContext == null; this.params = null; this.leafLookup = null; } else { this.leafLookup = lookup.getLeafSearchLookup(leafContext); params = new HashMap<>(params); params.putAll(leafLookup.asMap()); this.params = new ParameterMap(params, DEPRECATIONS); } }
LeafSearchLookup leafLookup = lookup.getLeafSearchLookup(context); Map<String, Object> ctx = new HashMap<>(leafLookup.asMap()); if (vars != null) { ctx.putAll(vars);
/** * Creates a ScriptImpl for the a previously compiled Painless script. * @param script The previously compiled Painless script. * @param vars The initial variables to run the script with. * @param lookup The lookup to allow search fields to be available if this is run as a search script. */ ScriptImpl(GenericElasticsearchScript script, Map<String, Object> vars, SearchLookup lookup, LeafReaderContext leafContext) { super(null, lookup, leafContext); this.script = script; this.variables = new HashMap<>(); if (vars != null) { variables.putAll(vars); } LeafSearchLookup leafLookup = getLeafLookup(); if (leafLookup != null) { variables.putAll(leafLookup.asMap()); } scoreLookup = script.needs_score() ? this::getScore : () -> 0.0; ctxLookup = script.needsCtx() ? variables -> (Map<?, ?>) variables.get("ctx") : variables -> null; }
@Override public LeafSearchScript getLeafSearchScript(LeafReaderContext context) throws IOException { final LeafSearchLookup leafLookup = lookup.getLeafSearchLookup(context); Map<String, Object> allVars = new HashMap<>(); allVars.putAll(leafLookup.asMap()); if (vars != null) { allVars.putAll(vars); } Script scriptObject; try { scriptObject = createScript(compiledScript.compiled(), allVars); } catch (InstantiationException | IllegalAccessException e) { throw new ScriptException("failed to build search " + compiledScript, e); } return new GroovyScript(compiledScript, scriptObject, leafLookup, logger); }