Class NumericMetadataFilter
- java.lang.Object
-
- com.norconex.importer.handler.AbstractImporterHandler
-
- com.norconex.importer.handler.filter.AbstractDocumentFilter
-
- com.norconex.importer.handler.filter.impl.NumericMetadataFilter
-
- All Implemented Interfaces:
IXMLConfigurable,IDocumentFilter,IOnMatchFilter,IImporterHandler
public class NumericMetadataFilter extends AbstractDocumentFilter
Accepts or rejects a document based on the numeric value(s) of matching metadata fields, supporting decimals. If multiple values are found for a field, only one of them needs to match for this filter to take effect. If the value is not a valid number, it is considered not to be matching. The decimal character is expected to be a dot. To reject decimals or to deal with non-numeric fields in your own way, you can use
TextFilter.XML configuration usage:
<handler class="com.norconex.importer.handler.filter.impl.NumericMetadataFilter" onMatch="[include|exclude]"> <!-- multiple "restrictTo" tags allowed (only one needs to match) --> <restrictTo> <fieldMatcher>(field-matching expression)</fieldMatcher> <valueMatcher>(value-matching expression)</valueMatcher> </restrictTo> <fieldMatcher>(expression matching numeric fields to filter)</fieldMatcher> <!-- Use one or two (for ranges) conditions, where possible operators are: gt -> greater than ge -> greater equal lt -> lower than le -> lowe equal eq -> equals --> <condition operator="[gt|ge|lt|le|eq]" number="(number)"/> </handler>XML usage example:
<handler class="NumericMetadataFilter" onMatch="include"> <fieldMatcher>age</fieldMatcher> <condition operator="ge" number="20"/> <condition operator="lt" number="30"/> </handler>Let's say you are importing customer profile documents and you have a field called "age" and you need to only consider documents for customers in their twenties (greater or equal to 20, but lower than 30). The above example would achieve that.
- Since:
- 2.2.0
- Author:
- Pascal Essiembre
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classNumericMetadataFilter.Conditionstatic classNumericMetadataFilter.Operator
-
Constructor Summary
Constructors Constructor Description NumericMetadataFilter()NumericMetadataFilter(TextMatcher fieldMatcher)Constructor.NumericMetadataFilter(TextMatcher fieldMatcher, OnMatch onMatch)NumericMetadataFilter(String field)Deprecated.Since 3.0.0, useNumericMetadataFilter(TextMatcher)NumericMetadataFilter(String field, OnMatch onMatch)Deprecated.Since 3.0.0, useNumericMetadataFilter(TextMatcher, OnMatch)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddCondition(NumericMetadataFilter.Operator operator, double number)booleanequals(Object other)List<NumericMetadataFilter.Condition>getConditions()StringgetField()Deprecated.Since 3.0.0, usegetFieldMatcher().TextMatchergetFieldMatcher()inthashCode()protected booleanisDocumentMatched(HandlerDoc doc, InputStream input, ParseState parseState)protected voidloadFilterFromXML(XML xml)protected voidsaveFilterToXML(XML xml)voidsetConditions(NumericMetadataFilter.Condition... conditions)voidsetField(String field)Deprecated.Since 3.0.0, usesetFieldMatcher(TextMatcher)voidsetFieldMatcher(TextMatcher fieldMatcher)StringtoString()-
Methods inherited from class com.norconex.importer.handler.filter.AbstractDocumentFilter
acceptDocument, getOnMatch, loadHandlerFromXML, saveHandlerToXML, setOnMatch
-
Methods inherited from class com.norconex.importer.handler.AbstractImporterHandler
addRestriction, addRestriction, addRestrictions, clearRestrictions, detectCharsetIfBlank, getRestrictions, isApplicable, loadFromXML, removeRestriction, removeRestriction, saveToXML
-
-
-
-
Constructor Detail
-
NumericMetadataFilter
public NumericMetadataFilter()
-
NumericMetadataFilter
@Deprecated public NumericMetadataFilter(String field)
Deprecated.Since 3.0.0, useNumericMetadataFilter(TextMatcher)Constructor.- Parameters:
field- field to apply numeric filtering
-
NumericMetadataFilter
@Deprecated public NumericMetadataFilter(String field, OnMatch onMatch)
Deprecated.Since 3.0.0, useNumericMetadataFilter(TextMatcher, OnMatch)Constructor.- Parameters:
field- field to apply numeric filteringonMatch- include or exclude on match
-
NumericMetadataFilter
public NumericMetadataFilter(TextMatcher fieldMatcher)
Constructor.- Parameters:
fieldMatcher- matcher for fields on which to apply date filtering- Since:
- 3.0.0
-
NumericMetadataFilter
public NumericMetadataFilter(TextMatcher fieldMatcher, OnMatch onMatch)
- Parameters:
fieldMatcher- matcher for fields on which to apply date filteringonMatch- include or exclude on match- Since:
- 3.0.0
-
-
Method Detail
-
getField
@Deprecated public String getField()
Deprecated.Since 3.0.0, usegetFieldMatcher().Deprecated.- Returns:
- field name
-
setField
@Deprecated public void setField(String field)
Deprecated.Since 3.0.0, usesetFieldMatcher(TextMatcher)Deprecated.- Parameters:
field- field name
-
getFieldMatcher
public TextMatcher getFieldMatcher()
-
setFieldMatcher
public void setFieldMatcher(TextMatcher fieldMatcher)
-
getConditions
public List<NumericMetadataFilter.Condition> getConditions()
-
setConditions
public void setConditions(NumericMetadataFilter.Condition... conditions)
-
addCondition
public void addCondition(NumericMetadataFilter.Operator operator, double number)
-
isDocumentMatched
protected boolean isDocumentMatched(HandlerDoc doc, InputStream input, ParseState parseState) throws ImporterHandlerException
- Specified by:
isDocumentMatchedin classAbstractDocumentFilter- Throws:
ImporterHandlerException
-
loadFilterFromXML
protected void loadFilterFromXML(XML xml)
- Specified by:
loadFilterFromXMLin classAbstractDocumentFilter
-
saveFilterToXML
protected void saveFilterToXML(XML xml)
- Specified by:
saveFilterToXMLin classAbstractDocumentFilter
-
equals
public boolean equals(Object other)
- Overrides:
equalsin classAbstractDocumentFilter
-
hashCode
public int hashCode()
- Overrides:
hashCodein classAbstractDocumentFilter
-
toString
public String toString()
- Overrides:
toStringin classAbstractDocumentFilter
-
-