MergeTransformer
Merge multiple metadata fields into a single one.
Notes
Each entry under operations selects source fields with a fieldMatcher and
writes their combined values to toField.
By default every value is added to the target field, making it multi-valued.
Set singleValue to true to combine them into one string instead, joined by
singleValueSeparator — or by nothing at all if no separator is given.
Set deleteFromFields to true to remove the source fields once merged. The
target field may itself be one of the source fields: its content is then
replaced by the merged result, and it survives even with deleteFromFields
enabled.
When the matcher finds only one field, its values are copied to the target and
still collapsed to a single value if configured to. That makes this handler an
alternative to
ForceSingleValueTransformer with a mergeWith
action.
Can be used both as a pre-parse or post-parse handler.
Examples
The following example merges several title fields into one, joining multiple occurrences with a coma, and deleting original fields.
- YAML
- JSON
- XML
handler:
class: MergeTransformer
operations:
- toField: title
deleteFromFields: true
singleValue: true
singleValueSeparator: ","
fieldMatcher:
method: REGEX
pattern: (title|dc.title|dc:title|doctitle)
{
"handler": {
"class": "MergeTransformer",
"operations": [
{
"toField": "title",
"deleteFromFields": true,
"singleValue": true,
"singleValueSeparator": ",",
"fieldMatcher": {
"method": "REGEX",
"pattern": "(title|dc.title|dc:title|doctitle)"
}
}
]
}
}
<handler>
<class>MergeTransformer</class>
<operations>
<op>
<toField>title</toField>
<deleteFromFields>true</deleteFromFields>
<singleValue>true</singleValue>
<singleValueSeparator>,</singleValueSeparator>
<fieldMatcher>
<method>REGEX</method>
<pattern>(title|dc.title|dc:title|doctitle)</pattern>
</fieldMatcher>
</op>
</operations>
</handler>
Usage
Full configuration skeleton, with every option and its default
- YAML
- JSON
- XML
class: MergeTransformer
label: string
operations:
- deleteFromFields: false
fieldMatcher: {}
singleValue: false
singleValueSeparator: string
toField: string
{
"class": "MergeTransformer",
"label": "string",
"operations": [
{
"deleteFromFields": false,
"fieldMatcher": {},
"singleValue": false,
"singleValueSeparator": "string",
"toField": "string"
}
]
}
<handler>
<class>MergeTransformer</class>
<label>string</label>
<operations>
<op>
<deleteFromFields>false</deleteFromFields>
<fieldMatcher/>
<singleValue>false</singleValue>
<singleValueSeparator>string</singleValueSeparator>
<toField>string</toField>
</op>
</operations>
</handler>
Properties
| Property | Type | Required | Default |
|---|---|---|---|
label | string | No | - |
operations | MergeOperation[] | No | - |
Property Details
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.
operations
One or more merges to perform, each naming the fields to merge, the field to merge them into, and whether to collapse the result to a single value. See MergeOperation.