Overview | Package | Class | Use | Tree | Deprecated | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.lucene.analysis.util
Class CharTokenizer

    java.lang.Object
      org.apache.lucene.util.AttributeSource
          org.apache.lucene.analysis.TokenStream
              org.apache.lucene.analysis.Tokenizer
                  org.apache.lucene.analysis.util.CharTokenizer

All Implemented Interfaces:
  Closeable

Direct Known Subclasses:
  IndicTokenizer, LetterTokenizer, RussianLetterTokenizer, WhitespaceTokenizer

    public abstract class CharTokenizer

extends Tokenizer

An abstract base class for simple, character-oriented tokenizers.

You must specify the required `Version` compatibility when creating `CharTokenizer`:

- As of 3.1, `CharTokenizer` uses an int based API to normalize and detect token codepoints. See `isTokenChar(int)` and `normalize(int)` for details.

A new `CharTokenizer` API has been introduced with Lucene 3.1. This API moved from UTF-16 code units to UTF-32 codepoints to eventually add support for supplementary characters. The old char based API has been deprecated and should be replaced with the int based methods `isTokenChar(int)` and `normalize(int)`.

As of Lucene 3.1 each `CharTokenizer` - constructor expects a `Version` argument. Based on the given `Version` either the new API or a backwards compatibility layer is used at runtime. For `Version` < 3.1 the backwards compatibility layer ensures correct behavior even for indexes build with previous versions of Lucene. If a `Version` >= 3.1 is used `CharTokenizer` requires the new API to be implemented by the instantiated class. Yet, the old char based API is not required anymore even if backwards compatibility must be preserved. `CharTokenizer` subclasses implementing the new API are fully backwards compatible if instantiated with `Version` < 3.1.

Note: If you use a subclass of `CharTokenizer` with `Version` >= 3.1 on an index build with a version < 3.1, created tokens might not be compatible with the terms in your index.

Nested Class Summary

Nested classes/interfaces inherited from class org.apache.lucene.util.AttributeSource
`AttributeSource.AttributeFactory, AttributeSource.State`

Field Summary

Fields inherited from class org.apache.lucene.analysis.Tokenizer
`input`

Constructor Summary
`CharTokenizer(Version matchVersion, AttributeSource.AttributeFactory factory, Reader input)` Creates a new `CharTokenizer` instance
`CharTokenizer(Version matchVersion, Reader input)` Creates a new `CharTokenizer` instance

Method Summary
`void` | `end()`
`boolean` | `incrementToken()`
`protected abstract boolean` | `isTokenChar(int c)` Returns true iff a codepoint should be included in a token.
`protected int` | `normalize(int c)` Called on each token character to normalize it before it is added to the token.
`void` | `reset()`

Methods inherited from class org.apache.lucene.analysis.Tokenizer
`close, correctOffset, setReader`

Methods inherited from class org.apache.lucene.util.AttributeSource
`addAttribute, addAttributeImpl, captureState, clearAttributes, cloneAttributes, copyTo, equals, getAttribute, getAttributeClassesIterator, getAttributeFactory, getAttributeImplsIterator, hasAttribute, hasAttributes, hashCode, reflectAsString, reflectWith, restoreState`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### CharTokenizer

    public CharTokenizer(Version matchVersion,
                         Reader input)

  Creates a new `CharTokenizer` instance

  Parameters:
    `matchVersion` - Lucene version to match
    `input` - the input to split up into tokens

### CharTokenizer

    public CharTokenizer(Version matchVersion,
                         AttributeSource.AttributeFactory factory,
                         Reader input)

  Creates a new `CharTokenizer` instance

  Parameters:
    `matchVersion` - Lucene version to match
    `factory` - the attribute factory to use for this `Tokenizer`
    `input` - the input to split up into tokens

Method Detail

### isTokenChar

    protected abstract boolean isTokenChar(int c)

  Returns true iff a codepoint should be included in a token. This tokenizer generates as tokens adjacent sequences of codepoints which satisfy this predicate. Codepoints for which this is false are used to define token boundaries and are not included in tokens.

### normalize

    protected int normalize(int c)

  Called on each token character to normalize it before it is added to the token. The default implementation does nothing. Subclasses may use this to, e.g., lowercase tokens.

### incrementToken

    public final boolean incrementToken()
                                 throws IOException

  Specified by:
    `incrementToken` in class `TokenStream`
  Throws:
    `IOException`

### end

    public final void end()

  Overrides:
    `end` in class `TokenStream`

### reset

    public void reset()
               throws IOException

  Overrides:
    `reset` in class `TokenStream`
  Throws:
    `IOException`

Overview | Package | Class | Use | Tree | Deprecated | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.