Dear Wiki user, You have subscribed to a wiki page or wiki category on "Solr Wiki" for change notification.
The "ScriptUpdateProcessor" page has been changed by ErikHatcher: http://wiki.apache.org/solr/ScriptUpdateProcessor?action=diff&rev1=6&rev2=7 Comment: Filling in some blanks = Introduction = - This feature ... + The ScriptUpdateProcessor enables update processing code to be written in a scripting language. The script can be written in any scripting language supported by your JVM (such as JavaScript), and executed dynamically so no pre-compilation is necessary. = Configuration = - The UpdateRequestProcessor is configured in solrconfig.xml. All parameters listed may also be overridded on the update request itself. A minimal configuration specifies the script file to use: + The UpdateRequestProcessor is configured in solrconfig.xml. All parameters listed may also be overridden on the update request itself. A minimal configuration specifies the script file to use: {{{ <updateRequestProcessorChain name="script"> <processor class="solr.StatelessScriptUpdateProcessorFactory"> <str name="script">update-script.js</str> </processor> + <!-- optional parameters passed to script + <lst name="params"> + <str name="config_param">example config parameter</str> + </lst> + --> + <processor class="solr.LogUpdateProcessorFactory" /> <processor class="solr.RunUpdateProcessorFactory" /> </updateRequestProcessorChain> }}} - '''NOTE:''' The processor supports the {{{defaults/appends/invariants}}} concept for its config. However, it is also possible to skip this level and configure the parameters directly underneath the {{{<processor>}}} tag. (?? is this true for the ScriptUpdateProcessor too? this verbiage borrowed from the language identification processor) + '''NOTE:''' The processor supports the {{{defaults/appends/invariants}}} concept for its config. However, it is also possible to skip this level and configure the parameters directly underneath the {{{<processor>}}} tag. Below follows a list of each configuration parameters and their meaning: == script == - The script file name. + The script file name. The script file must be placed in the conf/ directory. There can be one or more "script" parameters specified; multiple scripts are executed in the order specified. == engine == - Optionally specifies the scripting engine to use. This is only needed if the extension of the script file is not a standard mapping to the scripting engine. + Optionally specifies the scripting engine to use. This is only needed if the extension of the script file is not a standard mapping to the scripting engine. For example, if your script file was coded in JavaScript but the file name was called update-script.foo, use "javascript" as the engine name. == params == Optional parameters that are passed into the script execution context. This is specified as a named list (<lst>) structure with nested typed parameters. If specified, the script context will get a "params" object, otherwise there will be no "params" object available. @@ -50, +56 @@ !SolrQueryResponse (org.apache.solr.response.!SolrQueryResponse) instance. + === params === + + The "params" object, if any specified, from the configuration. + + = Examples = - note that processAdd() and the other script methods can return false to skip further processing of the document. + The processAdd() and the other script methods can return false to skip further processing of the document. All methods must be defined, though generally the processAdd() method is where the action is. + + == JavaScript == + + Note: There is a JavaScript example (update-script.js) built into the Solr 4 and up example collection1 configuration. Check solrconfig.xml and uncomment the update request processor definition to enable this feature. + + {{{ + function processAdd(cmd) { + + doc = cmd.solrDoc; // org.apache.solr.common.SolrInputDocument + id = doc.getFieldValue("id"); + logger.info("update-script#processAdd: id=" + id); + + // Set a field value: + // doc.setField("foo_s", "whatever"); + + // Get a configuration parameter: + // config_param = params.get('config_param'); // "params" only exists if processor configured with <lst name="params"> + + // Get a request parameter: + // some_param = req.getParams().get("some_param") + + // Add a field of field names that match a pattern: + // - Potentially useful to determine the fields/attributes represented in a result set, via faceting on field_name_ss + // field_names = doc.getFieldNames().toArray(); + // for(i=0; i < field_names.length; i++) { + // field_name = field_names[i]; + // if (/attr_.*/.test(field_name)) { doc.addField("attribute_ss", field_names[i]); } + // } + + } + + function processDelete(cmd) { + // no-op + } + + function processMergeIndexes(cmd) { + // no-op + } + + function processCommit(cmd) { + // no-op + } + + function processRollback(cmd) { + // no-op + } + + function finish() { + // no-op + } + }}} == JRuby == + TBD + == Jython == + TBD = Caveats =