Lucene.Net
3.0.3
Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
|
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. More...
Inherits Lucene.Net.Analysis.TokenFilter.
Classes | |
class | AnonymousClassSinkFilter |
class | SinkFilter |
A filter that decides which AttributeSource states to store in the sink. More... | |
class | SinkTokenStream |
Public Member Functions | |
TeeSinkTokenFilter (TokenStream input) | |
Instantiates a new TeeSinkTokenFilter. | |
SinkTokenStream | NewSinkTokenStream () |
Returns a new SinkTokenStream that receives all tokens consumed by this stream. | |
SinkTokenStream | NewSinkTokenStream (SinkFilter filter) |
Returns a new SinkTokenStream that receives all tokens consumed by this stream that pass the supplied filter. | |
void | AddSinkTokenStream (SinkTokenStream sink) |
Adds a SinkTokenStream created by another TeeSinkTokenFilter to this one. The supplied stream will also receive all consumed tokens. This method can be used to pass tokens from two different tees to one sink. | |
void | ConsumeAllTokens () |
TeeSinkTokenFilter passes all tokens to the added sinks when itself is consumed. To be sure, that all tokens from the input stream are passed to the sinks, you can call this methods. This instance is exhausted after this, but all sinks are instant available. | |
override bool | IncrementToken () |
Consumers (i.e., IndexWriter) use this method to advance the stream to the next token. Implementing classes must implement this method and update the appropriate Util.Attributes with the attributes of the next token. | |
override void | End () |
This method is called by the consumer after the last token has been consumed, after IncrementToken returned false (using the new TokenStream API). Streams implementing the old API should upgrade to use this feature. This method can be used to perform any end-of-stream operations, such as setting the final offset of a stream. The final offset of a stream might differ from the offset of the last token eg in case one or more whitespaces followed after the last token, but a WhitespaceTokenizer was used. | |
Public Member Functions inherited from Lucene.Net.Analysis.TokenFilter | |
override void | End () |
Performs end-of-stream operations, if any, and calls then end() on the input TokenStream.NOTE: Be sure to call super.end() first when overriding this method. | |
override void | Reset () |
Reset the filter as well as the input TokenStream. | |
Public Member Functions inherited from Lucene.Net.Analysis.TokenStream | |
void | Close () |
Releases resources associated with this stream. | |
void | Dispose () |
Public Member Functions inherited from Lucene.Net.Util.AttributeSource | |
AttributeSource () | |
An AttributeSource using the default attribute factory AttributeSource.AttributeFactory.DEFAULT_ATTRIBUTE_FACTORY. | |
AttributeSource (AttributeSource input) | |
An AttributeSource that uses the same attributes as the supplied one. | |
AttributeSource (AttributeFactory factory) | |
An AttributeSource using the supplied AttributeFactory for creating new IAttribute instances. | |
virtual IEnumerable< Type > | GetAttributeTypesIterator () |
Returns a new iterator that iterates the attribute classes in the same order they were added in. Signature for Java 1.5: public Iterator<Class<? extends Attribute>> getAttributeClassesIterator() | |
virtual IEnumerable< Attribute > | GetAttributeImplsIterator () |
Returns a new iterator that iterates all unique Attribute implementations. This iterator may contain less entries that GetAttributeTypesIterator, if one instance implements more than one Attribute interface. Signature for Java 1.5: public Iterator<AttributeImpl> getAttributeImplsIterator() | |
virtual void | AddAttributeImpl (Attribute att) |
Expert: Adds a custom AttributeImpl instance with one or more Attribute interfaces. | |
virtual T | AddAttribute< T > () |
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. | |
virtual bool | HasAttribute< T > () |
The caller must pass in a Class<? extends Attribute> value. Returns true, iff this AttributeSource contains the passed-in Attribute. | |
virtual T | GetAttribute< T > () |
The caller must pass in a Class<? extends Attribute> value. Returns the instance of the passed in Attribute contained in this AttributeSource | |
virtual void | ClearAttributes () |
Resets all Attributes in this AttributeSource by calling Attribute.Clear() on each Attribute implementation. | |
virtual State | CaptureState () |
Captures the state of all Attributes. The return value can be passed to RestoreState to restore the state of this or another AttributeSource. | |
virtual void | RestoreState (State state) |
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). | |
override int | GetHashCode () |
override bool | Equals (System.Object obj) |
override System.String | ToString () |
virtual AttributeSource | CloneAttributes () |
Performs a clone of all Attribute instances returned in a new AttributeSource instance. This method can be used to e.g. create another TokenStream with exactly the same attributes (using AttributeSource(AttributeSource)) | |
Additional Inherited Members | |
Protected Member Functions inherited from Lucene.Net.Analysis.TokenFilter | |
override void | Dispose (bool disposing) |
Properties inherited from Lucene.Net.Util.AttributeSource | |
virtual AttributeFactory | Factory [get] |
Returns the used AttributeFactory. | |
virtual bool | HasAttributes [get] |
Returns true, iff this AttributeSource has any attributes | |
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.
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, sink1
and sink2
will both get tokens from both reader1
and reader2
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 ConsumeAllTokens. This TokenFilter is exhausted after this. In the above example, change the example above to: ... 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.
Definition at line 68 of file TeeSinkTokenFilter.cs.
Lucene.Net.Analysis.TeeSinkTokenFilter.TeeSinkTokenFilter | ( | TokenStream | input | ) |
Instantiates a new TeeSinkTokenFilter.
Definition at line 80 of file TeeSinkTokenFilter.cs.
void Lucene.Net.Analysis.TeeSinkTokenFilter.AddSinkTokenStream | ( | SinkTokenStream | sink | ) |
Adds a SinkTokenStream created by another TeeSinkTokenFilter
to this one. The supplied stream will also receive all consumed tokens. This method can be used to pass tokens from two different tees to one sink.
Definition at line 106 of file TeeSinkTokenFilter.cs.
void Lucene.Net.Analysis.TeeSinkTokenFilter.ConsumeAllTokens | ( | ) |
TeeSinkTokenFilter
passes all tokens to the added sinks when itself is consumed. To be sure, that all tokens from the input stream are passed to the sinks, you can call this methods. This instance is exhausted after this, but all sinks are instant available.
Definition at line 126 of file TeeSinkTokenFilter.cs.
|
virtual |
This method is called by the consumer after the last token has been consumed, after IncrementToken returned false
(using the new TokenStream
API). Streams implementing the old API should upgrade to use this feature. This method can be used to perform any end-of-stream operations, such as setting the final offset of a stream. The final offset of a stream might differ from the offset of the last token eg in case one or more whitespaces followed after the last token, but a WhitespaceTokenizer was used.
<throws> IOException </throws>
Reimplemented from Lucene.Net.Analysis.TokenStream.
Definition at line 160 of file TeeSinkTokenFilter.cs.
|
virtual |
Consumers (i.e., IndexWriter) use this method to advance the stream to the next token. Implementing classes must implement this method and update the appropriate Util.Attributes with the attributes of the next token.
The producer must make no assumptions about the attributes after the method has been returned: the caller may arbitrarily change it. If the producer needs to preserve the state for subsequent calls, it can use AttributeSource.CaptureState to create a copy of the current attribute state.
This method is called for every token of a document, so an efficient implementation is crucial for good performance. To avoid calls to AttributeSource.AddAttribute{T}() and AttributeSource.GetAttribute{T}(), references to all Util.Attributes that this stream uses should be retrieved during instantiation.
To ensure that filters and consumers know which attributes are available, the attributes must be added during instantiation. Filters and consumers are not required to check for availability of attributes in IncrementToken().
Implements Lucene.Net.Analysis.TokenStream.
Definition at line 133 of file TeeSinkTokenFilter.cs.
SinkTokenStream Lucene.Net.Analysis.TeeSinkTokenFilter.NewSinkTokenStream | ( | ) |
Returns a new SinkTokenStream that receives all tokens consumed by this stream.
Definition at line 85 of file TeeSinkTokenFilter.cs.
SinkTokenStream Lucene.Net.Analysis.TeeSinkTokenFilter.NewSinkTokenStream | ( | SinkFilter | filter | ) |
Returns a new SinkTokenStream that receives all tokens consumed by this stream that pass the supplied filter.
Definition at line 95 of file TeeSinkTokenFilter.cs.