public class KeepOnlyTagger extends AbstractDocumentTagger
Keep only the metadata fields provided, delete all other ones. Exact field names (case-insensitive) to keep can be provided as well as a regular expression that matches one or many fields (since 2.1.0).
Note: Unless you have good reasons for doing otherwise, it is recommended to use this handler as one of the last ones to be executed. This is a good practice to ensure all metadata fields are available to other handlers that may require them even if they are not otherwise required.
Can be used both as a pre-parse or post-parse handler.
<handler
class="com.norconex.importer.handler.tagger.impl.KeepOnlyTagger">
<!-- 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>
<fieldMatcher
method="[basic|csv|wildcard|regex]"
ignoreCase="[false|true]"
ignoreDiacritic="[false|true]"
partial="[false|true]">
(one or more matching fields to keep)
</fieldMatcher>
</handler>
<handler
class="KeepOnlyTagger">
<fieldMatcher
method="regex">
(title|description)
</fieldMatcher>
</handler>
The above example keeps only the title and description fields from all extracted fields.
Pattern
Constructor and Description |
---|
KeepOnlyTagger() |
Modifier and Type | Method and Description |
---|---|
void |
addField(String field)
Deprecated.
Since 3.0.0, use
setFieldMatcher(TextMatcher) |
boolean |
equals(Object other) |
TextMatcher |
getFieldMatcher()
Gets field matcher.
|
List<String> |
getFields()
Deprecated.
Since 3.0.0, use
getFieldMatcher() |
String |
getFieldsRegex()
Deprecated.
Since 3.0.0, use
getFieldMatcher() |
int |
hashCode() |
protected void |
loadHandlerFromXML(XML xml)
Loads configuration settings specific to the implementing class.
|
void |
removeField(String field)
Deprecated.
Since 3.0.0, use
setFieldMatcher(TextMatcher) |
protected void |
saveHandlerToXML(XML xml)
Saves configuration settings specific to the implementing class.
|
void |
setFieldMatcher(TextMatcher fieldMatcher)
Sets field matcher.
|
void |
setFieldsRegex(String fieldsRegex)
Deprecated.
Since 3.0.0, use
setFieldMatcher(TextMatcher) |
void |
tagApplicableDocument(HandlerDoc doc,
InputStream document,
ParseState parseState) |
String |
toString() |
tagDocument
addRestriction, addRestriction, addRestrictions, clearRestrictions, detectCharsetIfBlank, getRestrictions, isApplicable, loadFromXML, removeRestriction, removeRestriction, saveToXML
public void tagApplicableDocument(HandlerDoc doc, InputStream document, ParseState parseState) throws ImporterHandlerException
tagApplicableDocument
in class AbstractDocumentTagger
ImporterHandlerException
public TextMatcher getFieldMatcher()
public void setFieldMatcher(TextMatcher fieldMatcher)
fieldMatcher
- field matcher@Deprecated public List<String> getFields()
getFieldMatcher()
@Deprecated public void addField(String field)
setFieldMatcher(TextMatcher)
field
- fields to add@Deprecated public void removeField(String field)
setFieldMatcher(TextMatcher)
field
- field to keep@Deprecated public String getFieldsRegex()
getFieldMatcher()
@Deprecated public void setFieldsRegex(String fieldsRegex)
setFieldMatcher(TextMatcher)
fieldsRegex
- field matcher pattern.protected void loadHandlerFromXML(XML xml)
AbstractImporterHandler
loadHandlerFromXML
in class AbstractImporterHandler
xml
- XML configurationprotected void saveHandlerToXML(XML xml)
AbstractImporterHandler
saveHandlerToXML
in class AbstractImporterHandler
xml
- the XMLpublic boolean equals(Object other)
equals
in class AbstractImporterHandler
public int hashCode()
hashCode
in class AbstractImporterHandler
public String toString()
toString
in class AbstractImporterHandler
Copyright © 2009–2023 Norconex Inc.. All rights reserved.