public class NumericMetadataFilter extends AbstractDocumentFilter
Accepts or rejects a document based on the numeric value(s) of a metadata
field, 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 RegexMetadataFilter
.
<filter class="com.norconex.importer.handler.filter.impl.NumericMetadataFilter" onMatch="[include|exclude]" field="(name of metadata field to match)" > <restrictTo caseSensitive="[false|true]" field="(name of header/metadata field name to match)"> (regular expression of value to match) </restrictTo> <!-- multiple "restrictTo" tags allowed (only one needs to match) --> <!-- 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)" /> </filter>
For example, 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 following would achieve that
<filter class="com.norconex.importer.handler.filter.impl.NumericMetadataFilter" onMatch="include" field="age" > <condition operator="ge" number="20" /> <condition operator="lt" number="30" /> </filter>
Modifier and Type | Class and Description |
---|---|
static class |
NumericMetadataFilter.Condition |
static class |
NumericMetadataFilter.Operator |
Constructor and Description |
---|
NumericMetadataFilter() |
NumericMetadataFilter(String field) |
NumericMetadataFilter(String field,
OnMatch onMatch) |
Modifier and Type | Method and Description |
---|---|
void |
addCondition(NumericMetadataFilter.Operator operator,
double number) |
boolean |
equals(Object other) |
List<NumericMetadataFilter.Condition> |
getConditions() |
String |
getField() |
int |
hashCode() |
protected boolean |
isDocumentMatched(String reference,
InputStream input,
ImporterMetadata metadata,
boolean parsed) |
protected void |
loadFilterFromXML(org.apache.commons.configuration.XMLConfiguration xml) |
protected void |
saveFilterToXML(EnhancedXMLStreamWriter writer) |
void |
setConditions(NumericMetadataFilter.Condition... conditions) |
void |
setField(String property) |
String |
toString() |
acceptDocument, getOnMatch, loadHandlerFromXML, saveHandlerToXML, setOnMatch
addRestriction, addRestriction, addRestrictions, clearRestrictions, detectCharsetIfBlank, getRestrictions, isApplicable, loadFromXML, removeRestriction, removeRestriction, saveToXML
public NumericMetadataFilter()
public NumericMetadataFilter(String field)
public String getField()
public void setField(String property)
public List<NumericMetadataFilter.Condition> getConditions()
public void setConditions(NumericMetadataFilter.Condition... conditions)
public void addCondition(NumericMetadataFilter.Operator operator, double number)
protected boolean isDocumentMatched(String reference, InputStream input, ImporterMetadata metadata, boolean parsed) throws ImporterHandlerException
isDocumentMatched
in class AbstractDocumentFilter
ImporterHandlerException
protected void loadFilterFromXML(org.apache.commons.configuration.XMLConfiguration xml) throws IOException
loadFilterFromXML
in class AbstractDocumentFilter
IOException
protected void saveFilterToXML(EnhancedXMLStreamWriter writer) throws XMLStreamException
saveFilterToXML
in class AbstractDocumentFilter
XMLStreamException
public boolean equals(Object other)
equals
in class AbstractDocumentFilter
public int hashCode()
hashCode
in class AbstractDocumentFilter
public String toString()
toString
in class AbstractDocumentFilter
Copyright © 2009–2021 Norconex Inc.. All rights reserved.