public class SearchContentFilter extends Object implements SearchContentHandler
Filtering implementation of SearchContentHandler that by default passes all messages on to the next delegate in the chain.
In this handler, all info will be passed onto a delegate handler. You can build up a chain of filters by using one filter as the delegate for another. When you over-ride a method in a filter, you can modify any state you wish. If you want that to propogate on, you should call the method on yourself via super.(), if not, just return.
It is your responsibility to ensure that the events emitted from your filter are sensible. In particular, start/end messages must be paired even after filtering.
// we have a handler from somewhere SearchContentHandler handler = ...; // now we are going to mutate all "score" notifications to Double instances // from strings SearchContentHandler filter = new SearchContentFilter() { public void addHitProperty(Object key, Object value) { if("score".equals(key)) { if(value instanceof String) { value = new Double(value); } } super(key, value); } };
Constructor and Description |
---|
SearchContentFilter(SearchContentHandler delegate) |
Modifier and Type | Method and Description |
---|---|
void |
addHitProperty(Object key,
Object value)
The
addHitProperty method adds a key/value pair
containing some property of a particular hit. |
void |
addSearchProperty(Object key,
Object value)
The
addSearchProperty method adds a key/value pair
containing some property of the overall search result. |
void |
addSubHitProperty(Object key,
Object value)
The
addSubHitProperty method adds a key/value pair
containing some property of a particular subhit. |
void |
endHeader()
The
endHeader method indicates the end of a
formatted header. |
void |
endHit()
The
endHit method indicates the end of a formatted
hit. |
void |
endSearch()
The
endSearch method indicates the end of useful
search information. |
void |
endSubHit()
The
endSubHit method indicates the end of a
formatted subhit. |
boolean |
getMoreSearches()
getMoreSearches returns the state of the
SearchContentHandler with respect to further
searches from its data source. |
void |
setDatabaseID(String databaseID)
setDatabaseID identifies the database searched by
a name, ID or URN. |
void |
setMoreSearches(boolean val)
setMoreSearches sets the state of the
SearchContentHandler 's expectation of receiving
more results. |
void |
setQueryID(String queryID)
setQueryID identifies the query sequence by a
name, ID or URN. |
void |
startHeader()
The
startHeader method indicates the start of a
formatted header. |
void |
startHit()
The
startHit method indicates the start of a
formatted hit. |
void |
startSearch()
The
startSearch method indicates the start of
useful search information. |
void |
startSubHit()
The
startSubHit method indicates the start of a
formatted subhit. |
public SearchContentFilter(SearchContentHandler delegate)
public void addHitProperty(Object key, Object value)
SearchContentHandler
addHitProperty
method adds a key/value pair
containing some property of a particular hit.addHitProperty
in interface SearchContentHandler
key
- an Object
.value
- an Object
.public void addSearchProperty(Object key, Object value)
SearchContentHandler
addSearchProperty
method adds a key/value pair
containing some property of the overall search result.addSearchProperty
in interface SearchContentHandler
key
- an Object
.value
- an Object
.public void addSubHitProperty(Object key, Object value)
SearchContentHandler
addSubHitProperty
method adds a key/value pair
containing some property of a particular subhit.addSubHitProperty
in interface SearchContentHandler
key
- an Object
.value
- an Object
.public void startHeader()
SearchContentHandler
startHeader
method indicates the start of a
formatted header. This usually contains information relevant to
the search as a whole.startHeader
in interface SearchContentHandler
public void endHeader()
SearchContentHandler
endHeader
method indicates the end of a
formatted header.endHeader
in interface SearchContentHandler
public void startHit()
SearchContentHandler
startHit
method indicates the start of a
formatted hit. This could be a single line, or a block of
lines.startHit
in interface SearchContentHandler
public void endHit()
SearchContentHandler
endHit
method indicates the end of a formatted
hit.endHit
in interface SearchContentHandler
public void startSearch()
SearchContentHandler
startSearch
method indicates the start of
useful search information.startSearch
in interface SearchContentHandler
public void endSearch()
SearchContentHandler
endSearch
method indicates the end of useful
search information.endSearch
in interface SearchContentHandler
public void startSubHit()
SearchContentHandler
startSubHit
method indicates the start of a
formatted subhit. There may be zero or more of these per hit.startSubHit
in interface SearchContentHandler
public void endSubHit()
SearchContentHandler
endSubHit
method indicates the end of a
formatted subhit.endSubHit
in interface SearchContentHandler
public void setQueryID(String queryID)
SearchContentHandler
setQueryID
identifies the query sequence by a
name, ID or URN.setQueryID
in interface SearchContentHandler
queryID
- a String
which should be an unique
identifer for the sequence.public void setDatabaseID(String databaseID)
SearchContentHandler
setDatabaseID
identifies the database searched by
a name, ID or URN.setDatabaseID
in interface SearchContentHandler
databaseID
- a String
which should be an unique
identifier for the database searched.public boolean getMoreSearches()
SearchContentHandler
getMoreSearches
returns the state of the
SearchContentHandler
with respect to further
searches from its data source. Used for handling streams of
search results.getMoreSearches
in interface SearchContentHandler
boolean
value.public void setMoreSearches(boolean val)
SearchContentHandler
setMoreSearches
sets the state of the
SearchContentHandler
's expectation of receiving
more results. Used for handling streams of search results.setMoreSearches
in interface SearchContentHandler
val
- a boolean
value.Copyright © 2014 BioJava. All rights reserved.