Lucene.Net
3.0.3
Lucene.Net is a .NET port of the Java Lucene Indexing Library
|
A TokenStream
enumerates the sequence of tokens, either from Fields of a Document or from query text. This is an abstract class. Concrete subclasses are:
TokenStream
whose input is a Reader; and TokenStream
whose input is another TokenStream
. A new TokenStream
API has been introduced with Lucene 2.9. This API has moved from being Token based to IAttribute based. While Token still exists in 2.9 as a convenience class, the preferred way to store the information of a Token is to use Util.Attributes. TokenStream
now extends AttributeSource, which provides access to all of the token IAttributes for the TokenStream
. Note that only one instance per Util.Attribute is created and reused for every token. This approach reduces object creation and allows local caching of references to the Util.Attributes. See IncrementToken() for further details. The workflow of the new TokenStream
API is as follows:
TokenStream
/TokenFilters which add/get attributes to/from the AttributeSource. TokenStream
To make sure 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(). You can find some example code for the new API in the analysis package level Javadoc. Sometimes it is desirable to capture a current state of a TokenStream
, e. g. for buffering purposes (see CachingTokenFilter, TeeSinkTokenFilter). For this usecase AttributeSource.CaptureState and AttributeSource.RestoreState can be used.
More...
Inherits Lucene.Net.Util.AttributeSource, and IDisposable.
Inherited by Lucene.Net.Analysis.Miscellaneous.EmptyTokenStream, Lucene.Net.Analysis.Miscellaneous.PatternAnalyzer.FastStringTokenizer, Lucene.Net.Analysis.Miscellaneous.PatternAnalyzer.RegexTokenizer, Lucene.Net.Analysis.Miscellaneous.PrefixAndSuffixAwareTokenFilter, Lucene.Net.Analysis.Miscellaneous.PrefixAwareTokenFilter, Lucene.Net.Analysis.Miscellaneous.SingleTokenTokenStream, Lucene.Net.Analysis.NumericTokenStream, Lucene.Net.Analysis.Shingle.ShingleMatrixFilter, Lucene.Net.Analysis.TeeSinkTokenFilter.SinkTokenStream, Lucene.Net.Analysis.TokenFilter, Lucene.Net.Analysis.Tokenizer, Lucene.Net.Index.Memory.MemoryIndex.KeywordTokenStream< T >, Lucene.Net.Search.Highlight.TokenSources.StoredTokenStream, and Lucene.Net.Spatial.Prefix.PrefixTreeStrategy.CellTokenStream.
Public Member Functions | |
abstract 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. | |
virtual 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. | |
virtual void | Reset () |
Resets this stream to the beginning. This is an optional operation, so subclasses may or may not implement this method. Reset() is not needed for the standard indexing process. However, if the tokens of a TokenStream are intended to be consumed more than once, it is necessary to implement Reset(). Note that if your TokenStream caches tokens and feeds them back again after a reset, it is imperative that you clone the tokens when you store them away (on the first pass) as well as when you return them (on future passes after Reset()). | |
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)) | |
Protected Member Functions | |
abstract void | Dispose (bool disposing) |
Additional Inherited Members | |
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 | |
A TokenStream
enumerates the sequence of tokens, either from Fields of a Document or from query text.
This is an abstract class. Concrete subclasses are:
TokenStream
whose input is a Reader; and TokenStream
whose input is another TokenStream
. A new TokenStream
API has been introduced with Lucene 2.9. This API has moved from being Token based to IAttribute based. While Token still exists in 2.9 as a convenience class, the preferred way to store the information of a Token is to use Util.Attributes.
TokenStream
now extends AttributeSource, which provides access to all of the token IAttributes for the TokenStream
. Note that only one instance per Util.Attribute is created and reused for every token. This approach reduces object creation and allows local caching of references to the Util.Attributes. See IncrementToken() for further details.
The workflow of the new TokenStream
API is as follows:
TokenStream
/TokenFilters which add/get attributes to/from the AttributeSource. TokenStream
To make sure 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().
You can find some example code for the new API in the analysis package level Javadoc.
Sometimes it is desirable to capture a current state of a TokenStream
, e. g. for buffering purposes (see CachingTokenFilter, TeeSinkTokenFilter). For this usecase AttributeSource.CaptureState and AttributeSource.RestoreState can be used.
Definition at line 77 of file TokenStream.cs.
void Lucene.Net.Analysis.TokenStream.Close | ( | ) |
Releases resources associated with this stream.
Definition at line 150 of file TokenStream.cs.
void Lucene.Net.Analysis.TokenStream.Dispose | ( | ) |
Definition at line 155 of file TokenStream.cs.
|
protectedpure virtual |
Implemented in Lucene.Net.Analysis.Shingle.ShingleMatrixFilter, Lucene.Net.Analysis.TeeSinkTokenFilter.SinkTokenStream, Lucene.Net.Analysis.NumericTokenStream, Lucene.Net.Analysis.Miscellaneous.PrefixAwareTokenFilter, Lucene.Net.Spatial.Prefix.PrefixTreeStrategy.CellTokenStream, Lucene.Net.Analysis.Tokenizer, Lucene.Net.Analysis.Miscellaneous.PrefixAndSuffixAwareTokenFilter, Lucene.Net.Search.Highlight.TokenSources.StoredTokenStream, Lucene.Net.Analysis.Miscellaneous.SingleTokenTokenStream, Lucene.Net.Analysis.TokenFilter, and Lucene.Net.Analysis.Miscellaneous.EmptyTokenStream.
|
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 in Lucene.Net.Analysis.CJK.CJKTokenizer, Lucene.Net.Analysis.TeeSinkTokenFilter.SinkTokenStream, Lucene.Net.Analysis.Standard.StandardTokenizer, Lucene.Net.Analysis.NGram.EdgeNGramTokenizer, Lucene.Net.Analysis.Cn.ChineseTokenizer, Lucene.Net.Analysis.TeeSinkTokenFilter, Lucene.Net.Analysis.NGram.NGramTokenizer, Lucene.Net.Analysis.CharTokenizer, Lucene.Net.Analysis.KeywordTokenizer, Lucene.Net.Analysis.CachingTokenFilter, and Lucene.Net.Analysis.TokenFilter.
Definition at line 130 of file TokenStream.cs.
|
pure 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().
Implemented in Lucene.Net.Analysis.Shingle.ShingleMatrixFilter, Lucene.Net.Analysis.TeeSinkTokenFilter.SinkTokenStream, Lucene.Net.Analysis.NumericTokenStream, Lucene.Net.Analysis.CJK.CJKTokenizer, Lucene.Net.Analysis.NGram.EdgeNGramTokenizer, Lucene.Net.Analysis.Shingle.ShingleFilter, Lucene.Net.Analysis.Standard.StandardTokenizer, Lucene.Net.Analysis.NGram.EdgeNGramTokenFilter, Lucene.Net.Analysis.Compound.CompoundWordTokenFilterBase, Lucene.Net.Analysis.TeeSinkTokenFilter, Lucene.Net.Analysis.StopFilter, Lucene.Net.Spatial.Prefix.PrefixTreeStrategy.CellTokenStream, Lucene.Net.Analysis.Cn.ChineseTokenizer, Lucene.Net.Analysis.NGram.NGramTokenizer, Lucene.Net.Analysis.Reverse.ReverseStringFilter, Lucene.Net.Analysis.NGram.NGramTokenFilter, Lucene.Net.Analysis.De.GermanStemFilter, Lucene.Net.Analysis.Nl.DutchStemFilter, Lucene.Net.Analysis.Miscellaneous.PrefixAwareTokenFilter, Lucene.Net.Analysis.Fr.ElisionFilter, Lucene.Net.Analysis.Fr.FrenchStemFilter, Lucene.Net.Analysis.Snowball.SnowballFilter, Lucene.Net.Analysis.Position.PositionFilter, Lucene.Net.Analysis.Cn.ChineseFilter, Lucene.Net.Analysis.CharTokenizer, Lucene.Net.Analysis.ASCIIFoldingFilter, Lucene.Net.Analysis.KeywordTokenizer, Lucene.Net.Analysis.Payloads.DelimitedPayloadTokenFilter, Lucene.Net.Analysis.Miscellaneous.PrefixAndSuffixAwareTokenFilter, Lucene.Net.Analysis.Th.ThaiWordFilter, Lucene.Net.Analysis.BR.BrazilianStemFilter, Lucene.Net.Analysis.Ru.RussianStemFilter, Lucene.Net.Search.Highlight.TokenSources.StoredTokenStream, Lucene.Net.Analysis.Hunspell.HunspellStemFilter, Lucene.Net.Analysis.PorterStemFilter, Lucene.Net.Analysis.Standard.StandardFilter, Lucene.Net.Analysis.Payloads.NumericPayloadTokenFilter, Lucene.Net.Analysis.AR.ArabicStemFilter, Lucene.Net.Analysis.ISOLatin1AccentFilter, Lucene.Net.Analysis.AR.ArabicNormalizationFilter, Lucene.Net.Analysis.Miscellaneous.SingleTokenTokenStream, Lucene.Net.Analysis.Payloads.TypeAsPayloadTokenFilter, Lucene.Net.Analysis.Fa.PersianNormalizationFilter, Lucene.Net.Analysis.Payloads.TokenOffsetPayloadTokenFilter, Lucene.Net.Analysis.LengthFilter, Lucene.Net.Analysis.Ru.RussianLowerCaseFilter, Lucene.Net.Analysis.El.GreekLowerCaseFilter, Lucene.Net.Analysis.CachingTokenFilter, Lucene.Net.Analysis.LowerCaseFilter, and Lucene.Net.Analysis.Miscellaneous.EmptyTokenStream.
|
virtual |
Resets this stream to the beginning. This is an optional operation, so subclasses may or may not implement this method. Reset() is not needed for the standard indexing process. However, if the tokens of a TokenStream
are intended to be consumed more than once, it is necessary to implement Reset(). Note that if your TokenStream caches tokens and feeds them back again after a reset, it is imperative that you clone the tokens when you store them away (on the first pass) as well as when you return them (on future passes after Reset()).
Reimplemented in Lucene.Net.Analysis.CJK.CJKTokenizer, Lucene.Net.Analysis.Shingle.ShingleFilter, Lucene.Net.Analysis.Shingle.ShingleMatrixFilter, Lucene.Net.Analysis.TeeSinkTokenFilter.SinkTokenStream, Lucene.Net.Analysis.Compound.CompoundWordTokenFilterBase, Lucene.Net.Analysis.NGram.EdgeNGramTokenizer, Lucene.Net.Analysis.NumericTokenStream, Lucene.Net.Analysis.NGram.EdgeNGramTokenFilter, Lucene.Net.Analysis.Cn.ChineseTokenizer, Lucene.Net.Analysis.Miscellaneous.PrefixAwareTokenFilter, Lucene.Net.Analysis.NGram.NGramTokenizer, Lucene.Net.Analysis.NGram.NGramTokenFilter, Lucene.Net.Analysis.Th.ThaiWordFilter, Lucene.Net.Analysis.Position.PositionFilter, Lucene.Net.Analysis.Hunspell.HunspellStemFilter, Lucene.Net.Analysis.CachingTokenFilter, Lucene.Net.Analysis.TokenFilter, Lucene.Net.Analysis.Miscellaneous.PrefixAndSuffixAwareTokenFilter, and Lucene.Net.Analysis.Miscellaneous.SingleTokenTokenStream.
Definition at line 144 of file TokenStream.cs.