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
.
<handler
class="com.norconex.importer.handler.filter.impl.NumericMetadataFilter"
onMatch="[include|exclude]">
<!-- multiple "restrictTo" tags allowed (only one needs to match) -->
<restrictTo>
<fieldMatcher
method="[basic|csv|wildcard|regex]"
ignoreCase="[false|true]"
ignoreDiacritic="[false|true]"
partial="[false|true]">
(field-matching expression)
</fieldMatcher>
<valueMatcher
method="[basic|csv|wildcard|regex]"
ignoreCase="[false|true]"
ignoreDiacritic="[false|true]"
partial="[false|true]">
(value-matching expression)
</valueMatcher>
</restrictTo>
<fieldMatcher
method="[basic|csv|wildcard|regex]"
ignoreCase="[false|true]"
ignoreDiacritic="[false|true]"
partial="[false|true]">
(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>
<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.
Modifier and Type | Class and Description |
---|---|
static class |
NumericMetadataFilter.Condition |
static class |
NumericMetadataFilter.Operator |
Constructor and Description |
---|
NumericMetadataFilter() |
NumericMetadataFilter(String field)
Deprecated.
Since 3.0.0, use
NumericMetadataFilter(TextMatcher) |
NumericMetadataFilter(String field,
OnMatch onMatch)
Deprecated.
Since 3.0.0, use
NumericMetadataFilter(TextMatcher, OnMatch) |
NumericMetadataFilter(TextMatcher fieldMatcher)
Constructor.
|
NumericMetadataFilter(TextMatcher fieldMatcher,
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()
Deprecated.
Since 3.0.0, use
getFieldMatcher() . |
TextMatcher |
getFieldMatcher() |
int |
hashCode() |
protected boolean |
isDocumentMatched(HandlerDoc doc,
InputStream input,
ParseState parseState) |
protected void |
loadFilterFromXML(XML xml) |
protected void |
saveFilterToXML(XML xml) |
void |
setConditions(NumericMetadataFilter.Condition... conditions) |
void |
setField(String field)
Deprecated.
Since 3.0.0, use
setFieldMatcher(TextMatcher) |
void |
setFieldMatcher(TextMatcher fieldMatcher) |
String |
toString() |
acceptDocument, getOnMatch, loadHandlerFromXML, saveHandlerToXML, setOnMatch
addRestriction, addRestriction, addRestrictions, clearRestrictions, detectCharsetIfBlank, getRestrictions, isApplicable, loadFromXML, removeRestriction, removeRestriction, saveToXML
public NumericMetadataFilter()
@Deprecated public NumericMetadataFilter(String field)
NumericMetadataFilter(TextMatcher)
field
- field to apply numeric filtering@Deprecated public NumericMetadataFilter(String field, OnMatch onMatch)
NumericMetadataFilter(TextMatcher, OnMatch)
field
- field to apply numeric filteringonMatch
- include or exclude on matchpublic NumericMetadataFilter(TextMatcher fieldMatcher)
fieldMatcher
- matcher for fields on which to apply date filteringpublic NumericMetadataFilter(TextMatcher fieldMatcher, OnMatch onMatch)
fieldMatcher
- matcher for fields on which to apply date filteringonMatch
- include or exclude on match@Deprecated public String getField()
getFieldMatcher()
.@Deprecated public void setField(String field)
setFieldMatcher(TextMatcher)
field
- field namepublic TextMatcher getFieldMatcher()
public void setFieldMatcher(TextMatcher fieldMatcher)
public List<NumericMetadataFilter.Condition> getConditions()
public void setConditions(NumericMetadataFilter.Condition... conditions)
public void addCondition(NumericMetadataFilter.Operator operator, double number)
protected boolean isDocumentMatched(HandlerDoc doc, InputStream input, ParseState parseState) throws ImporterHandlerException
isDocumentMatched
in class AbstractDocumentFilter
ImporterHandlerException
protected void loadFilterFromXML(XML xml)
loadFilterFromXML
in class AbstractDocumentFilter
protected void saveFilterToXML(XML xml)
saveFilterToXML
in class AbstractDocumentFilter
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–2023 Norconex Inc.. All rights reserved.