This TokenFilter provides the ability to set aside attribute states
that have already been analyzed. This is useful in situations where multiple fields share
many common analysis steps and then go their separate ways.
It is also useful for doing things like entity extraction or proper noun analysis as
part of the analysis workflow and saving off those tokens for use in another field.
and will both get tokens from both
and after whitespace tokenizer
and now we can further wrap any of these in extra analysis, and more "sources" can be inserted if desired.
It is important, that tees are consumed before sinks (in the above example, the field names must be
less the sink's field names). If you are not sure, which stream is consumed first, you can simply
add another sink and then pass all tokens to the sinks at once using {@link #consumeAllTokens}.
This TokenFilter is exhausted after this. In the above example, change
the example above to:
TeeSinkTokenFilter source1 = new TeeSinkTokenFilter(new WhitespaceTokenizer(reader1)); TeeSinkTokenFilter.SinkTokenStream sink1 = source1.newSinkTokenStream(); TeeSinkTokenFilter.SinkTokenStream sink2 = source1.newSinkTokenStream(); TeeSinkTokenFilter source2 = new TeeSinkTokenFilter(new WhitespaceTokenizer(reader2)); source2.addSinkTokenStream(sink1); source2.addSinkTokenStream(sink2); TokenStream final1 = new LowerCaseFilter(source1); TokenStream final2 = source2; TokenStream final3 = new EntityDetect(sink1); TokenStream final4 = new URLDetect(sink2); d.add(new Field("f1", final1)); d.add(new Field("f2", final2)); d.add(new Field("f3", final3)); d.add(new Field("f4", final4));In this example,
CopyC#
sink1
CopyC#
sink2
CopyC#
reader1
CopyC#
reader2
... TokenStream final1 = new LowerCaseFilter(source1.newSinkTokenStream()); TokenStream final2 = source2.newSinkTokenStream(); sink1.consumeAllTokens(); sink2.consumeAllTokens(); ...In this case, the fields can be added in any order, because the sources are not used anymore and all sinks are ready. Note, the EntityDetect and URLDetect TokenStreams are for the example and do not currently exist in Lucene.
The TeeSinkTokenFilter..::..SinkTokenStream type exposes the following members.
Methods
Name | Description | |
---|---|---|
AddAttribute | The caller must pass in a Class<? extends Attribute> value.
This method first checks if an instance of that class is
already in this AttributeSource and returns it. Otherwise a
new instance is created, added to this AttributeSource and returned.
Signature for Java 1.5: (Inherited from AttributeSource.)CopyC# public <T extends Attribute> T addAttribute(Class<T>) | |
AddAttributeImpl | Adds a custom AttributeImpl instance with one or more Attribute interfaces. (Inherited from AttributeSource.) | |
CaptureState | Captures the state of all Attributes. The return value can be passed to
{@link #restoreState} to restore the state of this or another AttributeSource.
(Inherited from AttributeSource.) | |
ClearAttributes | Resets all Attributes in this AttributeSource by calling
{@link AttributeImpl#Clear()} on each Attribute implementation.
(Inherited from AttributeSource.) | |
CloneAttributes | Performs a clone of all {@link AttributeImpl} instances returned in a new
AttributeSource instance. This method can be used to e.g. create another TokenStream
with exactly the same attributes (using {@link #AttributeSource(AttributeSource)})
(Inherited from AttributeSource.) | |
Close | Releases resources associated with this stream. (Inherited from TokenStream.) | |
End | (Overrides TokenStream..::..End()()()().) | |
Equals | (Inherited from AttributeSource.) | |
Finalize | Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.) | |
GetAttribute | The caller must pass in a Class<? extends Attribute> value.
Returns the instance of the passed in Attribute contained in this AttributeSource
Signature for Java 1.5: (Inherited from AttributeSource.)CopyC# public <T extends Attribute> T getAttribute(Class<T>) | |
GetAttributeClassesIterator | Returns a new iterator that iterates the attribute classes
in the same order they were added in.
Signature for Java 1.5: (Inherited from AttributeSource.)CopyC# public Iterator<Class<? extends Attribute>> getAttributeClassesIterator() | |
GetAttributeFactory | returns the used AttributeFactory. (Inherited from AttributeSource.) | |
GetAttributeImplsIterator | Returns a new iterator that iterates all unique Attribute implementations.
This iterator may contain less entries that {@link #getAttributeClassesIterator},
if one instance implements more than one Attribute interface.
Signature for Java 1.5: (Inherited from AttributeSource.)CopyC# public Iterator<AttributeImpl> getAttributeImplsIterator() | |
GetHashCode | (Inherited from AttributeSource.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
HasAttribute | The caller must pass in a Class<? extends Attribute> value.
Returns true, iff this AttributeSource contains the passed-in Attribute.
Signature for Java 1.5: (Inherited from AttributeSource.)CopyC# public boolean hasAttribute(Class<? extends Attribute>) | |
HasAttributes | Returns true, iff this AttributeSource has any attributes (Inherited from AttributeSource.) | |
IncrementToken | (Overrides TokenStream..::..IncrementToken()()()().) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
Next()()()() | Obsolete. Returns the next {@link Token} in the stream, or null at EOS.
(Inherited from TokenStream.) | |
Next(Token) | Obsolete. Returns the next token in the stream, or null at EOS. When possible, the
input Token should be used as the returned Token (this gives fastest
tokenization performance), but this is not required and a new Token may be
returned. Callers may re-use a single Token instance for successive calls
to this method.
This implicitly defines a "contract" between consumers (callers of this
method) and producers (implementations of this method that are the source
for tokens):
(Inherited from TokenStream.)
| |
Reset | (Overrides TokenStream..::..Reset()()()().) | |
RestoreState | Restores this state by copying the values of all attribute implementations
that this state contains into the attributes implementations of the targetStream.
The targetStream must contain a corresponding instance for each argument
contained in this state (e.g. it is not possible to restore the state of
an AttributeSource containing a TermAttribute into a AttributeSource using
a Token instance as implementation).
Note that this method does not affect attributes of the targetStream
that are not contained in this state. In other words, if for example
the targetStream contains an OffsetAttribute, but this state doesn't, then
the value of the OffsetAttribute remains unchanged. It might be desirable to
reset its value to the default, in which case the caller should first
call {@link TokenStream#ClearAttributes()} on the targetStream.
(Inherited from AttributeSource.) | |
ToString | (Inherited from AttributeSource.) |