public class StatelessScriptUpdateProcessorFactory extends UpdateRequestProcessorFactory implements SolrCoreAware
An update request processor factory that enables the use of update
processors implemented as scripts which can be loaded by the
SolrResourceLoader (usually via the
conf dir for
This factory requires at least one configuration parameter named
script which 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
value, and that value is
false then 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
ScriptEngine API 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:
Loggerthat can be used for logging purposes in the script
Internally this update processor uses JDK 6 scripting engine support,
Invocable implementations of
that can be loaded using the Solr Plugin ClassLoader may be used.
By default, the engine used for each script is determined by the filed
this can be overridden by specifying an explicit "engine" name init
param for the factory, which identifies a registered name of a
(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)
ScriptEngineManager is created for each
SolrQueryRequest defining a "global" scope for the script(s)
which is request specific. Separate
are then used to evaluate the script files, resulting in an "engine" scope
that is specific to each script.
A simple example...
<processor class="solr.StatelessScriptUpdateProcessorFactory"> <str name="script">updateProcessor.js</str> </processor>
A more complex example involving multiple scripts in different languages,
and a "params"
NamedList that will be put into the global
scope of each script...
<processor class="solr.StatelessScriptUpdateProcessorFactory"> <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="solr.StatelessScriptUpdateProcessorFactory"> <arr name="script"> <str name="script">first-processor.txt</str> <str name="script">second-processor.txt</str> </arr> <str name="engine">rhino</str> </processor>
|Constructor and Description|
|Modifier and Type||Method and Description|
public void init(NamedList args)
public UpdateRequestProcessor getInstance(SolrQueryRequest req, SolrQueryResponse rsp, UpdateRequestProcessor next)
Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.