public class ScriptUpdateProcessorFactory extends UpdateRequestProcessorFactory implements SolrCoreAwareAn update request processor factory that enables the use of update processors implemented as scripts which can be loaded from the configSet. Previously known as the StatelessScriptUpdateProcessorFactory.
This factory requires at least one configuration parameter named
scriptwhich may be the name of a script file as a string, or an array of multiple script files. If multiple script files are specified, they are executed sequentially in the order specified in the configuration -- as if multiple factories were configured sequentially
Each script file is expected to declare functions with the same name as each method in
UpdateRequestProcessor, using the same arguments. One slight deviation is in the optional return value from these functions: If a script function has a
booleanreturn value, and that value is
falsethen the processor will cleanly terminate processing of the command and return, without forwarding the command on to the next script or processor in the chain. Due to limitations in the
ScriptEngineAPI used by this factory, it can not enforce that all functions exist on initialization, so errors from missing functions will only be generated at runtime when the chain attempts to use them.
The factory may also be configured with an optional "params" argument, which can be an
NamedList(or array, or any other simple Java object) which will be put into the global scope for each script.
The following variables are define as global variables for each script:
- req - The
- rsp - The
- logger - A
Loggerthat can be used for logging purposes in the script
- params - The "params" init argument in the factory configuration (if any)
Internally this update processor uses JDK 6 scripting engine support, and any
ScriptEngineFactory. (This may be particularly useful if multiple engines are available for the same scripting language, and you wish to force the usage of a particular engine because of known quirks)
ScriptEngineManageris created for each
SolrQueryRequestdefining a "global" scope for the script(s) which is request specific. Separate
ScriptEngineinstances are then used to evaluate the script files, resulting in an "engine" scope that is specific to each script.
A simple example...
<processor class="org.apache.solr.scripting.update.ScriptUpdateProcessorFactory"> <str name="script">updateProcessor.js</str> </processor>
A more complex example involving multiple scripts in different languages, and a "params"
NamedListthat will be put into the global scope of each script...
<processor class="org.apache.solr.scripting.update.ScriptUpdateProcessorFactory"> <arr name="script"> <str name="script">first-processor.js</str> <str name="script">second-processor.py</str> </arr> <lst name="params"> <bool name="a_bool_value">true</bool> <int name="and_int_value">3</int> </lst> </processor>
An example where the script file extensions are ignored, and an explicit script engine is used....
<processor class="org.apache.solr.scripting.update.ScriptUpdateProcessorFactory"> <arr name="script"> <str name="script">first-processor.txt</str> <str name="script">second-processor.txt</str> </arr> <str name="engine">rhino</str> </processor>
- req - The
Constructors Constructor Description
All Methods Instance Methods Concrete Methods Modifier and Type Method Description
getInstance(SolrQueryRequest req, SolrQueryResponse rsp, UpdateRequestProcessor next)
public void init(org.apache.solr.common.util.NamedList<?> args)
public UpdateRequestProcessor getInstance(SolrQueryRequest req, SolrQueryResponse rsp, UpdateRequestProcessor next)