public class ReplaceTagger extends AbstractDocumentTagger
Replaces an existing metadata value with another one. The "toField" argument is optional.
It is possible to only keep values that changed from a replacement and
discard others by setting "discardUnchanged" to true
.
If a target field with the same name already exists for a document,
values will be added to the end of the existing value list.
It is possible to change this default behavior by supplying a
PropertySetter
.
Not specifying a "toValue" will delete the matches from sources values.
Can be used both as a pre-parse or post-parse handler.
You can specify whether matches should be made
against the whole field value or not (default). You can also specify whether
replacement should be attempted on first match only (default) or all
occurrences. This last option is only applicable when whole value matching
is false
.
<handler
class="com.norconex.importer.handler.tagger.impl.ReplaceTagger">
<!-- 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>
<!-- multiple replace tags allowed -->
<replace
toField="(optional target field name)"
onSet="[append|prepend|replace|optional]">
discardUnchanged="[false|true]">
<fieldMatcher
method="[basic|csv|wildcard|regex]"
ignoreCase="[false|true]"
ignoreDiacritic="[false|true]"
partial="[false|true]">
(one or more matching fields to have their values replaced)
</fieldMatcher>
<valueMatcher
method="[basic|csv|wildcard|regex]"
ignoreCase="[false|true]"
ignoreDiacritic="[false|true]"
replaceAll="[false|true]"
partial="[false|true]">
(one or more source values to replace)
</valueMatcher>
<toValue>(replacement value)</toValue>
</replace>
</handler>
<handler
class="ReplaceTagger">
<replace>
<fieldMatcher>fruit</fieldMatcher>
<valueMatcher
replaceAll="true">
apple
</valueMatcher>
<toValue>orange</toValue>
</replace>
</handler>
The following example replaces occurrences of "apple" to "orange" in the "fruit" field.
Modifier and Type | Class and Description |
---|---|
static class |
ReplaceTagger.Replacement |
Constructor and Description |
---|
ReplaceTagger() |
Modifier and Type | Method and Description |
---|---|
void |
addReplacement(ReplaceTagger.Replacement replacement)
Adds a replacement.
|
boolean |
equals(Object other) |
List<ReplaceTagger.Replacement> |
getReplacements() |
int |
hashCode() |
protected void |
loadHandlerFromXML(XML xml)
Loads configuration settings specific to the implementing class.
|
void |
removeReplacement(String fromField)
Deprecated.
|
protected void |
saveHandlerToXML(XML xml)
Saves configuration settings specific to the implementing class.
|
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 List<ReplaceTagger.Replacement> getReplacements()
@Deprecated public void removeReplacement(String fromField)
public void addReplacement(ReplaceTagger.Replacement replacement)
replacement
- the replacementprotected 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.