org.apache.solr.update.processor
Class StatelessScriptUpdateProcessorFactory

java.lang.Object
  extended by org.apache.solr.update.processor.UpdateRequestProcessorFactory
      extended by org.apache.solr.update.processor.StatelessScriptUpdateProcessorFactory
All Implemented Interfaces:
NamedListInitializedPlugin, SolrCoreAware

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 the SolrCore).

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 boolean return 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:

Internally this update processor uses JDK 6 scripting engine support, and any Invocable implementations of ScriptEngine 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 extension (ie: a *.js file will be treated as a JavaScript script) but this can be overridden by specifying an explicit "engine" name init param for the factory, which identifies a registered name of a 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)

A new ScriptEngineManager is created for each SolrQueryRequest defining a "global" scope for the script(s) which is request specific. Separate ScriptEngine instances 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>
 


Field Summary
static org.slf4j.Logger log
           
 
Constructor Summary
StatelessScriptUpdateProcessorFactory()
           
 
Method Summary
 UpdateRequestProcessor getInstance(SolrQueryRequest req, SolrQueryResponse rsp, UpdateRequestProcessor next)
           
 void inform(SolrCore core)
           
 void init(NamedList args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static org.slf4j.Logger log
Constructor Detail

StatelessScriptUpdateProcessorFactory

public StatelessScriptUpdateProcessorFactory()
Method Detail

init

public void init(NamedList args)
Specified by:
init in interface NamedListInitializedPlugin
Overrides:
init in class UpdateRequestProcessorFactory

getInstance

public UpdateRequestProcessor getInstance(SolrQueryRequest req,
                                          SolrQueryResponse rsp,
                                          UpdateRequestProcessor next)
Specified by:
getInstance in class UpdateRequestProcessorFactory

inform

public void inform(SolrCore core)
Specified by:
inform in interface SolrCoreAware


Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.