public class ScriptFilter extends AbstractStringFilter
Filter 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.The expected return value from your script is a boolean indicating whether the document was matched or not.
<handler
class="com.norconex.importer.handler.filter.impl.ScriptFilter"
maxReadSize="(max characters to read at once)"
sourceCharset="(character encoding)"
onMatch="[include|exclude]"
engineName="(script engine name)">
<!-- 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>
<handler
class="ScriptFilter">
<script>
<![CDATA[
var isAppleDoc = metadata.getString('fruit') == 'apple'
|| content.indexOf('Apple') > -1;
/*return*/ isAppleDoc;
]]>
</script>
</handler>
<handler
class="ScriptFilter"
engineName="lua">
<script>
<![CDATA[
local isAppleDoc = metadata:getString('fruit') == 'apple'
and content:find('Apple') ~= nil;
return isAppleDoc;
]]>
</script>
</handler>
ScriptRunner
Constructor and Description |
---|
ScriptFilter() |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other) |
String |
getEngineName() |
String |
getScript() |
int |
hashCode() |
protected boolean |
isStringContentMatching(HandlerDoc doc,
StringBuilder content,
ParseState parseState,
int sectionIndex) |
protected void |
loadStringFilterFromXML(XML xml)
Loads configuration settings specific to the implementing class.
|
protected void |
saveStringFilterToXML(XML xml)
Saves configuration settings specific to the implementing class.
|
void |
setEngineName(String engineName) |
void |
setScript(String script) |
String |
toString() |
getMaxReadSize, isTextDocumentMatching, loadCharStreamFilterFromXML, saveCharStreamFilterToXML, setMaxReadSize
getSourceCharset, isDocumentMatched, loadFilterFromXML, saveFilterToXML, setSourceCharset
acceptDocument, getOnMatch, loadHandlerFromXML, saveHandlerToXML, setOnMatch
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 boolean isStringContentMatching(HandlerDoc doc, StringBuilder content, ParseState parseState, int sectionIndex) throws ImporterHandlerException
isStringContentMatching
in class AbstractStringFilter
ImporterHandlerException
protected void saveStringFilterToXML(XML xml)
AbstractStringFilter
saveStringFilterToXML
in class AbstractStringFilter
xml
- the XMLprotected void loadStringFilterFromXML(XML xml)
AbstractStringFilter
loadStringFilterFromXML
in class AbstractStringFilter
xml
- XML configurationpublic boolean equals(Object other)
equals
in class AbstractStringFilter
public int hashCode()
hashCode
in class AbstractStringFilter
public String toString()
toString
in class AbstractStringFilter
Copyright © 2009–2023 Norconex Inc.. All rights reserved.