Class TruncateTransformer

java.lang.Object
com.norconex.importer.handler.transformer.impl.TruncateTransformer
All Implemented Interfaces:
Configurable<TruncateTransformerConfig>, ConfigurableDocHandler<TruncateTransformerConfig>, DocHandler

public class TruncateTransformer extends Object implements ConfigurableDocHandler<TruncateTransformerConfig>

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: