public class ScriptTagger extends AbstractStringTagger
Tag incoming documents using a scripting language.
The default script engine is JavaScript
.
Refer to ScriptRunner
for more information on using a scripting
language with Norconex Importer.
The following are variables made available to your script for each document:
maxReadSize
length).Properties
object.There are no expected return value from your script. Returning one has no effect.
<handler
class="com.norconex.importer.handler.tagger.impl.ScriptTagger"
engineName="(script engine name)"
maxReadSize="(max characters to read at once)"
sourceCharset="(character encoding)">
<!-- multiple "restrictTo" tags allowed (only one needs to match) -->
<restrictTo>
<fieldMatcher
method="[basic|csv|wildcard|regex]"
ignoreCase="[false|true]"
ignoreDiacritic="[false|true]"
partial="[false|true]">
(field-matching expression)
</fieldMatcher>
<valueMatcher
method="[basic|csv|wildcard|regex]"
ignoreCase="[false|true]"
ignoreDiacritic="[false|true]"
partial="[false|true]">
(value-matching expression)
</valueMatcher>
</restrictTo>
<script>(your script)</script>
</handler>
The following examples add new metadata field indicating which fruit is a document about.
<handler
class="ScriptTagger">
<script>
<![CDATA[
metadata.add('fruit', 'apple');
]]>
</script>
</handler>
<handler
class="ScriptTagger"
engineName="lua">
<script>
<![CDATA[
metadata:addString('fruit', {'apple'});
]]>
</script>
</handler>
ScriptRunner
Constructor and Description |
---|
ScriptTagger() |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other) |
String |
getEngineName() |
String |
getScript() |
int |
hashCode() |
protected void |
loadStringTaggerFromXML(XML xml)
Loads configuration settings specific to the implementing class.
|
protected void |
saveStringTaggerToXML(XML xml)
Saves configuration settings specific to the implementing class.
|
void |
setEngineName(String engineName) |
void |
setScript(String script) |
protected void |
tagStringContent(HandlerDoc doc,
StringBuilder content,
ParseState parseState,
int sectionIndex) |
String |
toString() |
getMaxReadSize, loadCharStreamTaggerFromXML, saveCharStreamTaggerToXML, setMaxReadSize, tagTextDocument
getSourceCharset, loadHandlerFromXML, saveHandlerToXML, setSourceCharset, tagApplicableDocument
tagDocument
addRestriction, addRestriction, addRestrictions, clearRestrictions, detectCharsetIfBlank, getRestrictions, isApplicable, loadFromXML, removeRestriction, removeRestriction, saveToXML
public String getEngineName()
public void setEngineName(String engineName)
public String getScript()
public void setScript(String script)
protected void tagStringContent(HandlerDoc doc, StringBuilder content, ParseState parseState, int sectionIndex) throws ImporterHandlerException
tagStringContent
in class AbstractStringTagger
ImporterHandlerException
protected void saveStringTaggerToXML(XML xml)
AbstractStringTagger
saveStringTaggerToXML
in class AbstractStringTagger
xml
- the XMLprotected void loadStringTaggerFromXML(XML xml)
AbstractStringTagger
loadStringTaggerFromXML
in class AbstractStringTagger
xml
- xml configurationpublic boolean equals(Object other)
equals
in class AbstractStringTagger
public int hashCode()
hashCode
in class AbstractStringTagger
public String toString()
toString
in class AbstractStringTagger
Copyright © 2009–2023 Norconex Inc.. All rights reserved.