Class JcmsTokenizer

java.lang.Object
org.apache.lucene.util.AttributeSource
org.apache.lucene.analysis.TokenStream
org.apache.lucene.analysis.Tokenizer
com.jalios.jcms.search.analysis.JcmsTokenizer
All Implemented Interfaces:
Closeable, AutoCloseable

public final class JcmsTokenizer extends org.apache.lucene.analysis.Tokenizer
A grammar-based tokenizer constructed with JFlex, based on lucene default ClassicTokenizer.

This should be a good tokenizer for most European-language documents:

  • Splits words at punctuation characters, removing punctuation. However, a dot that's not followed by whitespace is considered part of a token.
  • Splits words at hyphens, underscore and dash, unless there's a number in the token.
  • Recognizes email addresses and internet hostnames as one token.
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.apache.lucene.util.AttributeSource

    org.apache.lucene.util.AttributeSource.State
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final String[]
    String token types that correspond to token type int constants

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

    input

    Fields inherited from class org.apache.lucene.analysis.TokenStream

    DEFAULT_TOKEN_ATTRIBUTE_FACTORY
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance of the JcmsTokenizer.
    JcmsTokenizer(org.apache.lucene.util.AttributeFactory factory)
    Creates a new JcmsTokenizer with a given AttributeFactory
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    final void
    end()
     
    int
    Retrieve the max allowed token length
    final boolean
     
    void
     
    void
    setMaxTokenLength(int length)
    Set the max allowed token length.

    Methods inherited from class org.apache.lucene.analysis.Tokenizer

    correctOffset, setReader, setReaderTestPoint

    Methods inherited from class org.apache.lucene.util.AttributeSource

    addAttribute, addAttributeImpl, captureState, clearAttributes, cloneAttributes, copyTo, endAttributes, equals, getAttribute, getAttributeClassesIterator, getAttributeFactory, getAttributeImplsIterator, hasAttribute, hasAttributes, hashCode, reflectAsString, reflectWith, removeAllAttributes, restoreState, toString

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • JcmsTokenizer

      public JcmsTokenizer()
      Creates a new instance of the JcmsTokenizer. Attaches the input to the newly created JFlex scanner. See http://issues.apache.org/jira/browse/LUCENE-1068
    • JcmsTokenizer

      public JcmsTokenizer(org.apache.lucene.util.AttributeFactory factory)
      Creates a new JcmsTokenizer with a given AttributeFactory
      Parameters:
      factory - the attribute factory to use
  • Method Details

    • setMaxTokenLength

      public void setMaxTokenLength(int length)
      Set the max allowed token length. Any token longer than this is skipped.
      Parameters:
      length - a length, must be greated than zero, default is 255
    • getMaxTokenLength

      public int getMaxTokenLength()
      Retrieve the max allowed token length
      Returns:
      a length greater than 0, default is 255
      See Also:
    • incrementToken

      public final boolean incrementToken() throws IOException
      Specified by:
      incrementToken in class org.apache.lucene.analysis.TokenStream
      Throws:
      IOException
    • end

      public final void end() throws IOException
      Overrides:
      end in class org.apache.lucene.analysis.TokenStream
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class org.apache.lucene.analysis.Tokenizer
      Throws:
      IOException
    • reset

      public void reset() throws IOException
      Overrides:
      reset in class org.apache.lucene.analysis.Tokenizer
      Throws:
      IOException