Package org.dlese.dpc.index.analysis
Class PerFieldAnalyzer
java.lang.Object
org.apache.lucene.analysis.Analyzer
org.dlese.dpc.index.analysis.PerFieldAnalyzer
- All Implemented Interfaces:
Closeable,AutoCloseable
public class PerFieldAnalyzer
extends org.apache.lucene.analysis.Analyzer
This Analyzer is used to facilitate scenarios where different fields require different analysis
techniques. Use
to add a non-default Analyzer or
invalid reference
#addAnalyzer
addAnalyzersInBundle(java.util.ResourceBundle) to
provide a ResourceBundle to configure Analyzers on a field name basis. The ResourceBundle should contain
className=field1,field2,... pairs, where the field names are a comma-separated list, for example:
org.dlese.dpc.index.analysis.SnowballAnalyzer=stems,titlestems
- Author:
- John Weatherley
-
Field Summary
FieldsFields inherited from class org.apache.lucene.analysis.Analyzer
overridesTokenStreamMethod -
Constructor Summary
ConstructorsConstructorDescriptionConstructs using aStandardAnalyzeras the default for fields not otherwise configured.PerFieldAnalyzer(org.apache.lucene.analysis.Analyzer defaultAnalyzer) Constructs with the given Analyzer to use as a default for fields not otherwise configured. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAnalyzersInBundle(ResourceBundle fieldAnalyzerBundle) Adds the Analyzers to use for given fields, using the field=className pairs provided in the ResourceBundle, overrridding any previous ones if they existed.booleancontainsAnalyzer(String fieldName) Determines if an Analyzer is configured for the given field.org.apache.lucene.analysis.AnalyzergetAnalyzer(String fieldName) Gets the Analyzer configured for the given field, or null if none exists.org.apache.lucene.analysis.AnalyzerGets the default Analyzer being used.org.apache.lucene.analysis.AnalyzerremoveAnalyzer(String fieldName) Removes the Analyzer that is configured for the given field, if one exists.voidsetAnalyzer(String fieldName, String analyzerClassName) Sets the Analyzer to use for the specified search field, overridding the previous one if it existed.voidsetDefaultAnalyzer(org.apache.lucene.analysis.Analyzer analyzer) Sets the default Analyzer to use from here forth.org.apache.lucene.analysis.TokenStreamtokenStream(String fieldName, Reader reader) Generates a token stream for the given field.toString()Methods inherited from class org.apache.lucene.analysis.Analyzer
close, getOffsetGap, getPositionIncrementGap, getPreviousTokenStream, reusableTokenStream, setOverridesTokenStreamMethod, setPreviousTokenStream
-
Field Details
-
TEXT_ANALYZER
- See Also:
-
KEYWORD_ANALYZER
- See Also:
-
STEMS_ANALYZER
- See Also:
-
-
Constructor Details
-
PerFieldAnalyzer
public PerFieldAnalyzer(org.apache.lucene.analysis.Analyzer defaultAnalyzer) Constructs with the given Analyzer to use as a default for fields not otherwise configured. If null, aStandardAnalyzerwill be used as the default.- Parameters:
defaultAnalyzer- Any fields not specifically defined to use a different analyzer will use the one provided here.
-
PerFieldAnalyzer
public PerFieldAnalyzer()Constructs using aStandardAnalyzeras the default for fields not otherwise configured.
-
-
Method Details
-
setAnalyzer
public void setAnalyzer(String fieldName, String analyzerClassName) throws ClassNotFoundException, InstantiationException, IllegalAccessException Sets the Analyzer to use for the specified search field, overridding the previous one if it existed.- Parameters:
fieldName- field name requiring a non-default analyzer.analyzerClassName- Name of Analyzer class to use for the field- Throws:
ClassNotFoundException- If errorInstantiationException- If errorIllegalAccessException- If error
-
toString
-
addAnalyzersInBundle
public void addAnalyzersInBundle(ResourceBundle fieldAnalyzerBundle) throws ClassNotFoundException, InstantiationException, IllegalAccessException Adds the Analyzers to use for given fields, using the field=className pairs provided in the ResourceBundle, overrridding any previous ones if they existed. The ResourceBundle should contain className=field1,field2,... pairs, where the field names are a comma-separated list, for example:org.dlese.dpc.index.analysis.SnowballAnalyzer=stems,titlestems
- Parameters:
fieldAnalyzerBundle- A resource bundle containing className=field1,field2,etc. pairs- Throws:
ClassNotFoundException- If errorInstantiationException- If errorIllegalAccessException- If error
-
getAnalyzer
Gets the Analyzer configured for the given field, or null if none exists.- Parameters:
fieldName- The field name- Returns:
- The Analyzer
-
getDefaultAnalyzer
public org.apache.lucene.analysis.Analyzer getDefaultAnalyzer()Gets the default Analyzer being used.- Returns:
- The default Analyzer
-
setDefaultAnalyzer
public void setDefaultAnalyzer(org.apache.lucene.analysis.Analyzer analyzer) Sets the default Analyzer to use from here forth.- Parameters:
analyzer- The new default Analyzer
-
containsAnalyzer
Determines if an Analyzer is configured for the given field.- Parameters:
fieldName- The field name- Returns:
- True if an Analyzer is configured for the given field
-
removeAnalyzer
Removes the Analyzer that is configured for the given field, if one exists. After removing, the given will will use the default Analyzer.- Parameters:
fieldName- The field name- Returns:
- The Analyzer that was configured, or null
-
tokenStream
Generates a token stream for the given field.- Specified by:
tokenStreamin classorg.apache.lucene.analysis.Analyzer- Parameters:
fieldName- The field namereader- The Reader- Returns:
- The TokenStream appropriate for this field
-