Class ReplaceTagger

  • All Implemented Interfaces:
    IXMLConfigurable, IImporterHandler, IDocumentTagger

    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.

    Storing values in an existing field

    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.

    XML configuration usage:

    
    <handler
        class="com.norconex.importer.handler.tagger.impl.ReplaceTagger">
      <!-- multiple "restrictTo" tags allowed (only one needs to match) -->
      <restrictTo>
        <fieldMatcher>(field-matching expression)</fieldMatcher>
        <valueMatcher>(value-matching expression)</valueMatcher>
      </restrictTo>
      <!-- multiple replace tags allowed -->
      <replace
          toField="(optional target field name)">
        discardUnchanged="[false|true]">
        <fieldMatcher>
          (one or more matching fields to have their values replaced)
        </fieldMatcher>
        <valueMatcher>(one or more source values to replace)</valueMatcher>
        <toValue>(replacement value)</toValue>
      </replace>
    </handler>

    XML usage example:

    
    <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.

    Author:
    Pascal Essiembre