Class TruncateTransformerConfig

All Implemented Interfaces:
Labelable

public class TruncateTransformerConfig extends BaseDocHandlerConfig

Truncates a fromField value(s) and optionally replace truncated portion by a hash value to help ensure uniqueness (not 100% guaranteed to be collision-free). If the field to truncate has multiple values, all values will be subject to truncation. You can store the value(s), truncated or not, in another target field.

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.

The maxLength is guaranteed to be respected. This means any appended hash code and suffix will fit within the maxLength.

Truncating (or clearing) the document content

When no fieldMatcher is specified, this handler truncates the document content (body) instead of a field. Setting maxLength to 0 with no fieldMatcher effectively clears the document content entirely, while leaving its metadata untouched. Pair it with toField to first copy the content elsewhere (subject to the same maxLength) before it is cleared - use a large maxLength if the copy should not be truncated.

Can be used both as a pre-parse or post-parse handler.

Assuming this "myField" value...

    Please truncate me before you start thinking I am too long.

...the above example will truncate it to...

    Please truncate me before you start thi!0996700004
See Also:
  • Constructor Details

    • TruncateTransformerConfig

      public TruncateTransformerConfig()
  • Method Details

    • getFieldMatcher

      public TextMatcher getFieldMatcher()
      Gets the field matcher for fields to truncate. When unset (the default), the document content (body) is truncated instead.
      Returns:
      field matcher
    • setFieldMatcher

      public TruncateTransformerConfig setFieldMatcher(TextMatcher fieldMatcher)
      Sets the field matcher for fields to truncate. When unset (the default), the document content (body) is truncated instead.
      Parameters:
      fieldMatcher - field matcher
    • getMaxLength

      public int getMaxLength()
    • getToField

      public String getToField()
    • getOnSet

      public PropertySetter getOnSet()
      The property setter to use when a value is set.
      Returns:
      property setter
    • isAppendHash

      public boolean isAppendHash()
      Whether to apply the original string hash code at the end of the truncation to help ensure uniqueness (no guarantee).
    • getSuffix

      public String getSuffix()
    • setMaxLength

      public TruncateTransformerConfig setMaxLength(int maxLength)
      Returns:
      this.
    • setToField

      public TruncateTransformerConfig setToField(String toField)
      Returns:
      this.
    • setOnSet

      public TruncateTransformerConfig setOnSet(PropertySetter onSet)
      The property setter to use when a value is set.
      Parameters:
      onSet - property setter
      Returns:
      this.
    • setAppendHash

      public TruncateTransformerConfig setAppendHash(boolean appendHash)
      Whether to apply the original string hash code at the end of the truncation to help ensure uniqueness (no guarantee).
      Returns:
      this.
    • setSuffix

      public TruncateTransformerConfig setSuffix(String suffix)
      Returns:
      this.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class BaseLabelableConfig
    • canEqual

      protected boolean canEqual(Object other)
      Overrides:
      canEqual in class BaseLabelableConfig
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class BaseLabelableConfig
    • toString

      public String toString()
      Overrides:
      toString in class BaseLabelableConfig