ForceSingleValueTransformer
Forces a metadata field to be single-value
Notes
The action can be one of the following:
- keepFirst: Keeps the first occurrence found.
- keepLast: Keeps the last occurrence found.
- mergeWith:<sep>: Merges all values into one, separated by <sep>..
If you do not specify any action, the default behavior is to merge all occurrences, joining values with a comma.
Can be used both as a pre-parse or post-parse handler.
Examples
For documents where multiple title fields are found, The following example only keeps the first title value captured.
- YAML
- JSON
- XML
handler:
class: ExternalParser
action: keepFirst
fieldMatcher:
pattern: title
{
"handler": {
"class": "ExternalParser",
"action": "keepFirst",
"fieldMatcher": {
"pattern": "title"
}
}
}
<handler>
<class>ExternalParser</class>
<action>keepFirst</action>
<fieldMatcher>
<pattern>title</pattern>
</fieldMatcher>
</handler>
Usage
Full configuration skeleton, with every option and its default
- YAML
- JSON
- XML
class: ForceSingleValueTransformer
action: string
fieldMatcher:
ignoreCase: false
ignoreDiacritic: false
matchEmpty: false
method: BASIC
negateMatches: false
partial: false
pattern: string
replaceAll: false
trim: false
label: string
{
"class": "ForceSingleValueTransformer",
"action": "string",
"fieldMatcher": {
"ignoreCase": false,
"ignoreDiacritic": false,
"matchEmpty": false,
"method": "BASIC",
"negateMatches": false,
"partial": false,
"pattern": "string",
"replaceAll": false,
"trim": false
},
"label": "string"
}
<handler>
<class>ForceSingleValueTransformer</class>
<action>string</action>
<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>
</handler>
Properties
| Property | Type | Required | Default |
|---|---|---|---|
action | string | No | - |
fieldMatcher | TextMatcher | No | TextMatcher |
label | string | No | - |
Property Details
action
The action can be one of the following:
"action"="[keepFirst|keepLast|mergeWith:separator]"
- keepFirst: Keeps the first occurrence found.
- keepLast: Keeps the last occurrence found.
- mergeWith:<sep>: Merges all values into one, separated by <sep>..
If you do not specify any action, the default behavior is to merge all occurrences, joining values with a comma.
fieldMatcher
Matches document fields based on specified patterns and methods
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.