Skip to main content

CountMatchesTransformer

Counts the occurrences of matches within a field.

Notes

This functionality counts the occurrences of a specified string or string pattern and stores the resulting value in the target field defined by "toField.".

If no "fieldMatcher" expression is specified, the document content will be used. If the "fieldMatcher" matches more than one field, the sum of all matches will be stored as a single value. More often than not, you probably want to set your "countMatcher" to "partial".

Examples

The following example will count the number of segments in a URL.

handler:
class: CountMatchesTransformer
toField: urlSegmentCount
fieldMatcher:
pattern: document.reference
countMatcher:
method: REGEX
pattern: /[^/]+

Usage

Full configuration skeleton, with every option and its default
class: CountMatchesTransformer
countMatcher:
ignoreCase: false
ignoreDiacritic: false
matchEmpty: false
method: BASIC
negateMatches: false
partial: false
pattern: string
replaceAll: false
trim: false
fieldMatcher:
ignoreCase: false
ignoreDiacritic: false
matchEmpty: false
method: BASIC
negateMatches: false
partial: false
pattern: string
replaceAll: false
trim: false
label: string
maxReadSize: 0
onSet: APPEND
sourceCharset: string
toField: string

Properties

PropertyTypeRequiredDefault
countMatcherTextMatcherNoTextMatcher
fieldMatcherTextMatcherNoTextMatcher
labelstringNo-
maxReadSizeintegerNo10000000
onSetenumNo-
sourceCharsetstringNo-
toFieldstringNo-

Property Details

countMatcher

Counts occurrences of patterns in document fields.

fieldMatcher

Matches document fields based on specified patterns and methods. Use this to restrict the handler to operate only on fields whose names satisfy the matcher criteria.

label

An optional, user-supplied label for this step in the importer pipeline. It has no effect on processing — it exists purely to help identify this step, for example in large configurations or in the visual configurator.

maxReadSize

The maximum number of characters to read from the document content at once. Use this to limit memory usage when processing large documents.

onSet

Defines what to do when the target field already has one or more values. When unspecified, new values are appended to existing ones by default.

Allowed Values

  • APPEND
  • PREPEND
  • REPLACE
  • OPTIONAL

sourceCharset

Sets the character encoding of the source document to ensure proper reading and processing.

toField

A target field name used to store the value.