Interface Filter
-
- All Superinterfaces:
NamedFilter
- All Known Subinterfaces:
BytesDocumentFilter
,StringDocumentFilter
public interface Filter extends NamedFilter
Filters a document.A Filter can take a single document change it and return a new document by returning: a
FilterResult
. A filter result can either consist of zero documents (removing the document possibly stopping it from being stored, one document that may have been the result of editing the given document, many documents which may be the result of splitting the given document orFilterResult.skipped()
to mark that this filter is making no changes and should be considered skipped.Typically it is simpler to implement
StringDocumentFilter
orBytesDocumentFilter
than it is to implement this.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description FilterResult
filter(FilterableDocument document, FilterContext context)
Filter a document.-
Methods inherited from interface com.funnelback.filter.api.filters.NamedFilter
getFilterName
-
-
-
-
Method Detail
-
filter
FilterResult filter(FilterableDocument document, FilterContext context) throws RuntimeException, FilterException
Filter a document.Typically the interfaces
BytesDocumentFilter
orStringDocumentFilter
are implemented instead ofFilter
as they gives easier access to the document content. This interface should be implemented when the filter does not need to read or modify the documents content.Filtering only throws unchecked exceptions. In the case a unchecked exception is thrown filtering for that document is stopped and the document may or not be stored. When an exception is raised in a filter the filter can choose to:
- Re-throw the exception as a unchecked exception, ideally as a
FilterException
. - Return
FilterResult.isSkipped()
to indicate that the filter should be considered skipped, in the case of a choice filter this will cause it to try the next filter. - Ignore the exception and return any other type of
FilterResult
with or without changes to the given document.
FilterResult.skipped()
.- Parameters:
document
- The document to be filtered.context
- The context the filter is running under.- Returns:
- A
FilterResult
which comes from one of the static methods onFilterResult
. - Throws:
RuntimeException
- when a programming error occurs and the filtering of the given document should be considered a failure. Within gathering this may stop the document from being stored, however other documents will continue to be filtered.FilterException
- when an error occurs during the filtering of the document, and the document should not be filtered any further. Within gathering this may stop the document from being stored, howeber other documents will contine to be filtered.
- Re-throw the exception as a unchecked exception, ideally as a
-
-