Skip to main content

ScriptTransformer

Transformer incoming documents using a scripting language.

Notesโ€‹

The default script engine is JavaScript.

Refer to ScriptRunner for more information on using a scripting language with Norconex Importer.

How to tag documents with scripting:โ€‹

The following are variables made available to your script for each document:

  • reference: Document unique reference as a string.
  • content: Document content, as a string (of maxReadSize length).
  • metadata: Document metadata as an Properties object.
  • parsed: Whether the document was already parsed, as a boolean.
  • sectionIndex: Content section index if it had to be split, as an integer. There are no expected return value from your script. Returning one has no effect.

Examplesโ€‹

The following examples add new metadata field indicating which fruit is the document about.

JavaScript

handler:
class: ScriptTransformer
script: <![CDATA[metadata.add('fruit', 'apple');]]

luaโ€‹

LUA

handler:
class: ScriptTransformer
engineName: LUA
script: <![CDATA[metadata:addString('fruit', {'apple'});]]>

Usageโ€‹

Full configuration skeleton, with every option and its default
class: ScriptTransformer
engineName: string
fieldMatcher:
ignoreCase: false
ignoreDiacritic: false
matchEmpty: false
method: BASIC
negateMatches: false
partial: false
pattern: string
replaceAll: false
trim: false
label: string
maxReadSize: 0
script: string
sourceCharset: string

Propertiesโ€‹

PropertyTypeRequiredDefault
engineNamestringNo-
fieldMatcherTextMatcherNoTextMatcher
labelstringNo-
maxReadSizeintegerNo10000000
scriptstringNo-
sourceCharsetstringNo-

Property Detailsโ€‹

engineNameโ€‹

Which scripting engine runs the script. JavaScript, lua and velocity are available out of the box; any other JSR-223 engine on the classpath can be named here, such as python with Jython installed. Required โ€” there is no default.

fieldMatcherโ€‹

Matches document fields based on specified patterns and methods

labelโ€‹

An optional, user-supplied label for this step in the importer pipeline. It has no effect on processing โ€” it exists purely to help identify this step, for example in large configurations or in the visual configurator.

maxReadSizeโ€‹

Max characters to read at once

scriptโ€‹

The script content or path to execute as part of this handler's processing logic.

sourceCharsetโ€‹

Sets the character encoding of the source document to ensure proper reading and processing.