@Deprecated public final class PatternAnalyzer extends Analyzer
Reader
, that can flexibly separate text into terms via a regular expression Pattern
(with behaviour identical to String.split(String)
),
and that combines the functionality of
LetterTokenizer
,
LowerCaseTokenizer
,
WhitespaceTokenizer
,
StopFilter
into a single efficient
multi-purpose class.
If you are unsure how exactly a regular expression should look like, consider
prototyping by simply trying various expressions on some test texts via
String.split(String)
. Once you are satisfied, give that regex to
PatternAnalyzer. Also see Java Regular Expression Tutorial.
This class can be considerably faster than the "normal" Lucene tokenizers.
It can also serve as a building block in a compound Lucene
TokenFilter
chain. For example as in this
stemming example:
PatternAnalyzer pat = ... TokenStream tokenStream = new SnowballFilter( pat.tokenStream("content", "James is running round in the woods"), "English"));
Analyzer.GlobalReuseStrategy, Analyzer.PerFieldReuseStrategy, Analyzer.ReuseStrategy, Analyzer.TokenStreamComponents
Modifier and Type | Field and Description |
---|---|
static PatternAnalyzer |
DEFAULT_ANALYZER
Deprecated.
A lower-casing word analyzer with English stop words (can be shared
freely across threads without harm); global per class loader.
|
static PatternAnalyzer |
EXTENDED_ANALYZER
Deprecated.
A lower-casing word analyzer with extended English stop words
(can be shared freely across threads without harm); global per class
loader.
|
static Pattern |
NON_WORD_PATTERN
Deprecated.
"\\W+" ; Divides text at non-letters (NOT Character.isLetter(c)) |
static Pattern |
WHITESPACE_PATTERN
Deprecated.
"\\s+" ; Divides text at whitespaces (Character.isWhitespace(c)) |
GLOBAL_REUSE_STRATEGY, PER_FIELD_REUSE_STRATEGY
Constructor and Description |
---|
PatternAnalyzer(Version matchVersion,
Pattern pattern,
boolean toLowerCase,
CharArraySet stopWords)
Deprecated.
Constructs a new instance with the given parameters.
|
Modifier and Type | Method and Description |
---|---|
Analyzer.TokenStreamComponents |
createComponents(String fieldName,
Reader reader)
Deprecated.
Creates a token stream that tokenizes all the text in the given Reader;
This implementation forwards to
tokenStream(String, Reader, String) and is
less efficient than tokenStream(String, Reader, String) . |
Analyzer.TokenStreamComponents |
createComponents(String fieldName,
Reader reader,
String text)
Deprecated.
Creates a token stream that tokenizes the given string into token terms
(aka words).
|
boolean |
equals(Object other)
Deprecated.
Indicates whether some other object is "equal to" this one.
|
int |
hashCode()
Deprecated.
Returns a hash code value for the object.
|
close, getOffsetGap, getPositionIncrementGap, getReuseStrategy, getVersion, initReader, setVersion, tokenStream, tokenStream
public static final Pattern NON_WORD_PATTERN
"\\W+"
; Divides text at non-letters (NOT Character.isLetter(c))public static final Pattern WHITESPACE_PATTERN
"\\s+"
; Divides text at whitespaces (Character.isWhitespace(c))public static final PatternAnalyzer DEFAULT_ANALYZER
public static final PatternAnalyzer EXTENDED_ANALYZER
public PatternAnalyzer(Version matchVersion, Pattern pattern, boolean toLowerCase, CharArraySet stopWords)
matchVersion
- currently does nothingpattern
- a regular expression delimiting tokenstoLowerCase
- if true
returns tokens after applying
String.toLowerCase()stopWords
- if non-null, ignores all tokens that are contained in the
given stop set (after previously having applied toLowerCase()
if applicable). For example, created via
StopFilter.makeStopSet(Version, String[])
and/or
WordlistLoader
as in
WordlistLoader.getWordSet(new File("samples/fulltext/stopwords.txt")
or other stop words
lists .public Analyzer.TokenStreamComponents createComponents(String fieldName, Reader reader, String text)
fieldName
- the name of the field to tokenize (currently ignored).reader
- reader (e.g. charfilter) of the original text. can be null.text
- the string to tokenizepublic Analyzer.TokenStreamComponents createComponents(String fieldName, Reader reader)
tokenStream(String, Reader, String)
and is
less efficient than tokenStream(String, Reader, String)
.createComponents
in class Analyzer
fieldName
- the name of the field to tokenize (currently ignored).reader
- the reader delivering the textpublic boolean equals(Object other)
Copyright © 2000-2014 Apache Software Foundation. All Rights Reserved.