Class ForceSingleValueTagger
- java.lang.Object
-
- com.norconex.importer.handler.AbstractImporterHandler
-
- com.norconex.importer.handler.tagger.AbstractDocumentTagger
-
- com.norconex.importer.handler.tagger.impl.ForceSingleValueTagger
-
- All Implemented Interfaces:
IXMLConfigurable
,IImporterHandler
,IDocumentTagger
public class ForceSingleValueTagger extends AbstractDocumentTagger
Forces a metadata field to be single-value. The action can be one of the following:
Can be used both as a pre-parse or post-parse handler.
keepFirst Keeps the first occurrence found. keepLast Keeps the first occurrence found. mergeWith:<sep> Merges all occurrences, joining them with the specified separator (<sep>).
If you do not specify any action, the default behavior is to merge all occurrences, joining values with a comma.
XML configuration usage:
<handler class="com.norconex.importer.handler.tagger.impl.ForceSingleValueTagger" action="[keepFirst|keepLast|mergeWith:separator]"> <!-- multiple "restrictTo" tags allowed (only one needs to match) --> <restrictTo> <fieldMatcher>(field-matching expression)</fieldMatcher> <valueMatcher>(value-matching expression)</valueMatcher> </restrictTo> <fieldMatcher> (one or more matching fields to force having a single value) </fieldMatcher> </handler>
XML usage example:
<handler class="ForceSingleValueTagger" action="keepFirst"> <fieldMatcher>title</fieldMatcher> </handler>
For documents where multiple title fields are found, the above only keeps the first title value captured.
- Author:
- Pascal Essiembre
-
-
Constructor Summary
Constructors Constructor Description ForceSingleValueTagger()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addSingleValueField(String field, String action)
Deprecated.Since 3.0.0, usesetFieldMatcher(TextMatcher)
andsetAction(String)
.boolean
equals(Object other)
String
getAction()
Gets action.TextMatcher
getFieldMatcher()
Gets field matcher.Map<String,String>
getSingleValueFields()
Deprecated.Since 3.0.0, usegetFieldMatcher()
.int
hashCode()
protected void
loadHandlerFromXML(XML xml)
Loads configuration settings specific to the implementing class.void
removeSingleValueField(String name)
Deprecated.Since 3.0.0, usesetFieldMatcher(TextMatcher)
.protected void
saveHandlerToXML(XML xml)
Saves configuration settings specific to the implementing class.void
setAction(String action)
Sets the action.void
setFieldMatcher(TextMatcher fieldMatcher)
Sets field matcher.void
tagApplicableDocument(HandlerDoc doc, InputStream document, ParseState parseState)
String
toString()
-
Methods inherited from class com.norconex.importer.handler.tagger.AbstractDocumentTagger
tagDocument
-
Methods inherited from class com.norconex.importer.handler.AbstractImporterHandler
addRestriction, addRestriction, addRestrictions, clearRestrictions, detectCharsetIfBlank, getRestrictions, isApplicable, loadFromXML, removeRestriction, removeRestriction, saveToXML
-
-
-
-
Method Detail
-
tagApplicableDocument
public void tagApplicableDocument(HandlerDoc doc, InputStream document, ParseState parseState) throws ImporterHandlerException
- Specified by:
tagApplicableDocument
in classAbstractDocumentTagger
- Throws:
ImporterHandlerException
-
getFieldMatcher
public TextMatcher getFieldMatcher()
Gets field matcher.- Returns:
- field matcher
- Since:
- 3.0.0
-
setFieldMatcher
public void setFieldMatcher(TextMatcher fieldMatcher)
Sets field matcher.- Parameters:
fieldMatcher
- field matcher- Since:
- 3.0.0
-
getAction
public String getAction()
Gets action.- Returns:
- action action to be performed
- Since:
- 3.0.0
-
setAction
public void setAction(String action)
Sets the action. One of: keepFirst, keepLast, or mergeWith:<sep>.- Parameters:
action
- action to be performed- Since:
- 3.0.0
-
getSingleValueFields
@Deprecated public Map<String,String> getSingleValueFields()
Deprecated.Since 3.0.0, usegetFieldMatcher()
.Deprecated.- Returns:
- empty map
-
addSingleValueField
@Deprecated public void addSingleValueField(String field, String action)
Deprecated.Since 3.0.0, usesetFieldMatcher(TextMatcher)
andsetAction(String)
.Add a field to be made single value.- Parameters:
field
- fieldaction
- action
-
removeSingleValueField
@Deprecated public void removeSingleValueField(String name)
Deprecated.Since 3.0.0, usesetFieldMatcher(TextMatcher)
.Does nothing.- Parameters:
name
- field name
-
loadHandlerFromXML
protected void loadHandlerFromXML(XML xml)
Description copied from class:AbstractImporterHandler
Loads configuration settings specific to the implementing class.- Specified by:
loadHandlerFromXML
in classAbstractImporterHandler
- Parameters:
xml
- XML configuration
-
saveHandlerToXML
protected void saveHandlerToXML(XML xml)
Description copied from class:AbstractImporterHandler
Saves configuration settings specific to the implementing class.- Specified by:
saveHandlerToXML
in classAbstractImporterHandler
- Parameters:
xml
- the XML
-
equals
public boolean equals(Object other)
- Overrides:
equals
in classAbstractImporterHandler
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classAbstractImporterHandler
-
toString
public String toString()
- Overrides:
toString
in classAbstractImporterHandler
-
-