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.
- YAML
- JSON
- XML
handler:
class: CountMatchesTransformer
toField: urlSegmentCount
fieldMatcher:
pattern: document.reference
countMatcher:
method: REGEX
pattern: /[^/]+
{
"handler": {
"class": "CountMatchesTransformer",
"toField": "urlSegmentCount",
"fieldMatcher": {
"pattern": "document.reference"
},
"countMatcher": {
"method": "REGEX",
"pattern": "/[^/]+"
}
}
}
<handler>
<class>CountMatchesTransformer</class>
<toField>urlSegmentCount</toField>
<fieldMatcher>
<pattern>document.reference</pattern>
</fieldMatcher>
<countMatcher>
<method>REGEX</method>
<pattern>/[^/]+</pattern>
</countMatcher>
</handler>
Usage
Full configuration skeleton, with every option and its default
- YAML
- JSON
- XML
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
{
"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"
}
<handler>
<class>CountMatchesTransformer</class>
<countMatcher>
<ignoreCase>false</ignoreCase>
<ignoreDiacritic>false</ignoreDiacritic>
<matchEmpty>false</matchEmpty>
<method>BASIC</method>
<negateMatches>false</negateMatches>
<partial>false</partial>
<pattern>string</pattern>
<replaceAll>false</replaceAll>
<trim>false</trim>
</countMatcher>
<fieldMatcher>
<ignoreCase>false</ignoreCase>
<ignoreDiacritic>false</ignoreDiacritic>
<matchEmpty>false</matchEmpty>
<method>BASIC</method>
<negateMatches>false</negateMatches>
<partial>false</partial>
<pattern>string</pattern>
<replaceAll>false</replaceAll>
<trim>false</trim>
</fieldMatcher>
<label>string</label>
<maxReadSize>0</maxReadSize>
<onSet>APPEND</onSet>
<sourceCharset>string</sourceCharset>
<toField>string</toField>
</handler>
Properties
| Property | Type | Required | Default |
|---|---|---|---|
countMatcher | TextMatcher | No | TextMatcher |
fieldMatcher | TextMatcher | No | TextMatcher |
label | string | No | - |
maxReadSize | integer | No | 10000000 |
onSet | enum | No | - |
sourceCharset | string | No | - |
toField | string | No | - |
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
APPENDPREPENDREPLACEOPTIONAL
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.