Class CustomAnalyzer.Builder
- java.lang.Object
-
- org.apache.lucene.analysis.custom.CustomAnalyzer.Builder
-
- Enclosing class:
- CustomAnalyzer
public static final class CustomAnalyzer.Builder extends java.lang.ObjectBuilder forCustomAnalyzer.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<CharFilterFactory>charFiltersprivate booleancomponentsAddedprivate SetOnce<Version>defaultMatchVersionprivate ResourceLoaderloaderprivate SetOnce<java.lang.Integer>offsetGapprivate SetOnce<java.lang.Integer>posIncGapprivate java.util.List<TokenFilterFactory>tokenFiltersprivate SetOnce<TokenizerFactory>tokenizer
-
Constructor Summary
Constructors Constructor Description Builder(ResourceLoader loader)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CustomAnalyzer.BuilderaddCharFilter(java.lang.Class<? extends CharFilterFactory> factory, java.lang.String... params)Adds the given char filter.CustomAnalyzer.BuilderaddCharFilter(java.lang.Class<? extends CharFilterFactory> factory, java.util.Map<java.lang.String,java.lang.String> params)Adds the given char filter.CustomAnalyzer.BuilderaddCharFilter(java.lang.String name, java.lang.String... params)Adds the given char filter.CustomAnalyzer.BuilderaddCharFilter(java.lang.String name, java.util.Map<java.lang.String,java.lang.String> params)Adds the given char filter.CustomAnalyzer.BuilderaddTokenFilter(java.lang.Class<? extends TokenFilterFactory> factory, java.lang.String... params)Adds the given token filter.CustomAnalyzer.BuilderaddTokenFilter(java.lang.Class<? extends TokenFilterFactory> factory, java.util.Map<java.lang.String,java.lang.String> params)Adds the given token filter.CustomAnalyzer.BuilderaddTokenFilter(java.lang.String name, java.lang.String... params)Adds the given token filter.CustomAnalyzer.BuilderaddTokenFilter(java.lang.String name, java.util.Map<java.lang.String,java.lang.String> params)Adds the given token filter.private CustomAnalyzer.BuilderaddTokenFilter(TokenFilterFactory factory)private java.util.Map<java.lang.String,java.lang.String>applyDefaultParams(java.util.Map<java.lang.String,java.lang.String> map)(package private) <T> TapplyResourceLoader(T factory)CustomAnalyzerbuild()Builds the analyzer.private java.util.Map<java.lang.String,java.lang.String>paramsToMap(java.lang.String... params)CustomAnalyzer.ConditionBuilderwhen(java.lang.Class<? extends ConditionalTokenFilterFactory> factory, java.lang.String... params)Add aConditionalTokenFilterFactoryto the analysis chain TokenFilters added by subsequent calls toCustomAnalyzer.ConditionBuilder.addTokenFilter(String, String...)and related functions will only be used if the current token matches the condition.CustomAnalyzer.ConditionBuilderwhen(java.lang.Class<? extends ConditionalTokenFilterFactory> factory, java.util.Map<java.lang.String,java.lang.String> params)Add aConditionalTokenFilterFactoryto the analysis chain TokenFilters added by subsequent calls toCustomAnalyzer.ConditionBuilder.addTokenFilter(String, String...)and related functions will only be used if the current token matches the condition.CustomAnalyzer.ConditionBuilderwhen(java.lang.String name, java.lang.String... params)Add aConditionalTokenFilterFactoryto the analysis chain TokenFilters added by subsequent calls toCustomAnalyzer.ConditionBuilder.addTokenFilter(String, String...)and related functions will only be used if the current token matches the condition.CustomAnalyzer.ConditionBuilderwhen(java.lang.String name, java.util.Map<java.lang.String,java.lang.String> params)Add aConditionalTokenFilterFactoryto the analysis chain TokenFilters added by subsequent calls toCustomAnalyzer.ConditionBuilder.addTokenFilter(String, String...)and related functions will only be used if the current token matches the condition.CustomAnalyzer.ConditionBuilderwhen(ConditionalTokenFilterFactory factory)Add aConditionalTokenFilterFactoryto the analysis chain TokenFilters added by subsequent calls toCustomAnalyzer.ConditionBuilder.addTokenFilter(String, String...)and related functions will only be used if the current token matches the condition.CustomAnalyzer.ConditionBuilderwhenTerm(java.util.function.Predicate<java.lang.CharSequence> predicate)Apply subsequent token filters if the current token's term matches a predicate This is the equivalent of:CustomAnalyzer.BuilderwithDefaultMatchVersion(Version version)This match version is passed as default to all tokenizers or filters.CustomAnalyzer.BuilderwithOffsetGap(int offsetGap)Sets the offset gap of the analyzer.CustomAnalyzer.BuilderwithPositionIncrementGap(int posIncGap)Sets the position increment gap of the analyzer.CustomAnalyzer.BuilderwithTokenizer(java.lang.Class<? extends TokenizerFactory> factory, java.lang.String... params)Uses the given tokenizer.CustomAnalyzer.BuilderwithTokenizer(java.lang.Class<? extends TokenizerFactory> factory, java.util.Map<java.lang.String,java.lang.String> params)Uses the given tokenizer.CustomAnalyzer.BuilderwithTokenizer(java.lang.String name, java.lang.String... params)Uses the given tokenizer.CustomAnalyzer.BuilderwithTokenizer(java.lang.String name, java.util.Map<java.lang.String,java.lang.String> params)Uses the given tokenizer.
-
-
-
Field Detail
-
loader
private final ResourceLoader loader
-
charFilters
private final java.util.List<CharFilterFactory> charFilters
-
tokenizer
private final SetOnce<TokenizerFactory> tokenizer
-
tokenFilters
private final java.util.List<TokenFilterFactory> tokenFilters
-
posIncGap
private final SetOnce<java.lang.Integer> posIncGap
-
offsetGap
private final SetOnce<java.lang.Integer> offsetGap
-
componentsAdded
private boolean componentsAdded
-
-
Constructor Detail
-
Builder
Builder(ResourceLoader loader)
-
-
Method Detail
-
withDefaultMatchVersion
public CustomAnalyzer.Builder withDefaultMatchVersion(Version version)
This match version is passed as default to all tokenizers or filters. It is used unless you pass the parameter {code luceneMatchVersion} explicitly. It defaults to undefined, so the underlying factory will (in most cases) useVersion.LATEST.
-
withPositionIncrementGap
public CustomAnalyzer.Builder withPositionIncrementGap(int posIncGap)
Sets the position increment gap of the analyzer. The default is defined in the analyzer base class.- See Also:
Analyzer.getPositionIncrementGap(String)
-
withOffsetGap
public CustomAnalyzer.Builder withOffsetGap(int offsetGap)
Sets the offset gap of the analyzer. The default is defined in the analyzer base class.- See Also:
Analyzer.getOffsetGap(String)
-
withTokenizer
public CustomAnalyzer.Builder withTokenizer(java.lang.Class<? extends TokenizerFactory> factory, java.lang.String... params) throws java.io.IOException
Uses the given tokenizer.- Parameters:
factory- class that is used to create the tokenizer.params- a list of factory string params as key/value pairs. The number of parameters must be an even number, as they are pairs.- Throws:
java.io.IOException
-
withTokenizer
public CustomAnalyzer.Builder withTokenizer(java.lang.Class<? extends TokenizerFactory> factory, java.util.Map<java.lang.String,java.lang.String> params) throws java.io.IOException
Uses the given tokenizer.- Parameters:
factory- class that is used to create the tokenizer.params- the map of parameters to be passed to factory. The map must be modifiable.- Throws:
java.io.IOException
-
withTokenizer
public CustomAnalyzer.Builder withTokenizer(java.lang.String name, java.lang.String... params) throws java.io.IOException
Uses the given tokenizer.- Parameters:
name- is used to look up the factory withTokenizerFactory.forName(String, Map). The list of possible names can be looked up withTokenizerFactory.availableTokenizers().params- a list of factory string params as key/value pairs. The number of parameters must be an even number, as they are pairs.- Throws:
java.io.IOException
-
withTokenizer
public CustomAnalyzer.Builder withTokenizer(java.lang.String name, java.util.Map<java.lang.String,java.lang.String> params) throws java.io.IOException
Uses the given tokenizer.- Parameters:
name- is used to look up the factory withTokenizerFactory.forName(String, Map). The list of possible names can be looked up withTokenizerFactory.availableTokenizers().params- the map of parameters to be passed to factory. The map must be modifiable.- Throws:
java.io.IOException
-
addTokenFilter
public CustomAnalyzer.Builder addTokenFilter(java.lang.Class<? extends TokenFilterFactory> factory, java.lang.String... params) throws java.io.IOException
Adds the given token filter.- Parameters:
factory- class that is used to create the token filter.params- a list of factory string params as key/value pairs. The number of parameters must be an even number, as they are pairs.- Throws:
java.io.IOException
-
addTokenFilter
public CustomAnalyzer.Builder addTokenFilter(java.lang.Class<? extends TokenFilterFactory> factory, java.util.Map<java.lang.String,java.lang.String> params) throws java.io.IOException
Adds the given token filter.- Parameters:
factory- class that is used to create the token filter.params- the map of parameters to be passed to factory. The map must be modifiable.- Throws:
java.io.IOException
-
addTokenFilter
public CustomAnalyzer.Builder addTokenFilter(java.lang.String name, java.lang.String... params) throws java.io.IOException
Adds the given token filter.- Parameters:
name- is used to look up the factory withTokenFilterFactory.forName(String, Map). The list of possible names can be looked up withTokenFilterFactory.availableTokenFilters().params- a list of factory string params as key/value pairs. The number of parameters must be an even number, as they are pairs.- Throws:
java.io.IOException
-
addTokenFilter
public CustomAnalyzer.Builder addTokenFilter(java.lang.String name, java.util.Map<java.lang.String,java.lang.String> params) throws java.io.IOException
Adds the given token filter.- Parameters:
name- is used to look up the factory withTokenFilterFactory.forName(String, Map). The list of possible names can be looked up withTokenFilterFactory.availableTokenFilters().params- the map of parameters to be passed to factory. The map must be modifiable.- Throws:
java.io.IOException
-
addTokenFilter
private CustomAnalyzer.Builder addTokenFilter(TokenFilterFactory factory)
-
addCharFilter
public CustomAnalyzer.Builder addCharFilter(java.lang.Class<? extends CharFilterFactory> factory, java.lang.String... params) throws java.io.IOException
Adds the given char filter.- Parameters:
factory- class that is used to create the char filter.params- a list of factory string params as key/value pairs. The number of parameters must be an even number, as they are pairs.- Throws:
java.io.IOException
-
addCharFilter
public CustomAnalyzer.Builder addCharFilter(java.lang.Class<? extends CharFilterFactory> factory, java.util.Map<java.lang.String,java.lang.String> params) throws java.io.IOException
Adds the given char filter.- Parameters:
factory- class that is used to create the char filter.params- the map of parameters to be passed to factory. The map must be modifiable.- Throws:
java.io.IOException
-
addCharFilter
public CustomAnalyzer.Builder addCharFilter(java.lang.String name, java.lang.String... params) throws java.io.IOException
Adds the given char filter.- Parameters:
name- is used to look up the factory withCharFilterFactory.forName(String, Map). The list of possible names can be looked up withCharFilterFactory.availableCharFilters().params- a list of factory string params as key/value pairs. The number of parameters must be an even number, as they are pairs.- Throws:
java.io.IOException
-
addCharFilter
public CustomAnalyzer.Builder addCharFilter(java.lang.String name, java.util.Map<java.lang.String,java.lang.String> params) throws java.io.IOException
Adds the given char filter.- Parameters:
name- is used to look up the factory withCharFilterFactory.forName(String, Map). The list of possible names can be looked up withCharFilterFactory.availableCharFilters().params- the map of parameters to be passed to factory. The map must be modifiable.- Throws:
java.io.IOException
-
when
public CustomAnalyzer.ConditionBuilder when(java.lang.String name, java.lang.String... params) throws java.io.IOException
Add aConditionalTokenFilterFactoryto the analysis chain TokenFilters added by subsequent calls toCustomAnalyzer.ConditionBuilder.addTokenFilter(String, String...)and related functions will only be used if the current token matches the condition. Consumers must callCustomAnalyzer.ConditionBuilder.endwhen()to return to the normal tokenfilter chain once conditional filters have been added- Parameters:
name- is used to look up the factory withTokenFilterFactory.forName(String, Map)params- the parameters to be passed to the factory- Throws:
java.io.IOException
-
when
public CustomAnalyzer.ConditionBuilder when(java.lang.String name, java.util.Map<java.lang.String,java.lang.String> params) throws java.io.IOException
Add aConditionalTokenFilterFactoryto the analysis chain TokenFilters added by subsequent calls toCustomAnalyzer.ConditionBuilder.addTokenFilter(String, String...)and related functions will only be used if the current token matches the condition. Consumers must callCustomAnalyzer.ConditionBuilder.endwhen()to return to the normal tokenfilter chain once conditional filters have been added- Parameters:
name- is used to look up the factory withTokenFilterFactory.forName(String, Map)params- the parameters to be passed to the factory. The map must be modifiable- Throws:
java.io.IOException
-
when
public CustomAnalyzer.ConditionBuilder when(java.lang.Class<? extends ConditionalTokenFilterFactory> factory, java.lang.String... params) throws java.io.IOException
Add aConditionalTokenFilterFactoryto the analysis chain TokenFilters added by subsequent calls toCustomAnalyzer.ConditionBuilder.addTokenFilter(String, String...)and related functions will only be used if the current token matches the condition. Consumers must callCustomAnalyzer.ConditionBuilder.endwhen()to return to the normal tokenfilter chain once conditional filters have been added- Parameters:
factory- class that is used to create the ConditionalTokenFilterparams- the parameters to be passed to the factory- Throws:
java.io.IOException
-
when
public CustomAnalyzer.ConditionBuilder when(java.lang.Class<? extends ConditionalTokenFilterFactory> factory, java.util.Map<java.lang.String,java.lang.String> params) throws java.io.IOException
Add aConditionalTokenFilterFactoryto the analysis chain TokenFilters added by subsequent calls toCustomAnalyzer.ConditionBuilder.addTokenFilter(String, String...)and related functions will only be used if the current token matches the condition. Consumers must callCustomAnalyzer.ConditionBuilder.endwhen()to return to the normal tokenfilter chain once conditional filters have been added- Parameters:
factory- class that is used to create the ConditionalTokenFilterparams- the parameters to be passed to the factory. The map must be modifiable- Throws:
java.io.IOException
-
when
public CustomAnalyzer.ConditionBuilder when(ConditionalTokenFilterFactory factory)
Add aConditionalTokenFilterFactoryto the analysis chain TokenFilters added by subsequent calls toCustomAnalyzer.ConditionBuilder.addTokenFilter(String, String...)and related functions will only be used if the current token matches the condition. Consumers must callCustomAnalyzer.ConditionBuilder.endwhen()to return to the normal tokenfilter chain once conditional filters have been added
-
whenTerm
public CustomAnalyzer.ConditionBuilder whenTerm(java.util.function.Predicate<java.lang.CharSequence> predicate)
Apply subsequent token filters if the current token's term matches a predicate This is the equivalent of:when(new ConditionalTokenFilterFactory(Collections.emptyMap()) {@Override protected ConditionalTokenFilter create(TokenStream input, Function<TokenStream, TokenStream> inner) { return new ConditionalTokenFilter(input, inner) { CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);@Override protected boolean shouldFilter() { return predicate.test(termAtt); } }; } });
-
build
public CustomAnalyzer build()
Builds the analyzer.
-
applyDefaultParams
private java.util.Map<java.lang.String,java.lang.String> applyDefaultParams(java.util.Map<java.lang.String,java.lang.String> map)
-
paramsToMap
private java.util.Map<java.lang.String,java.lang.String> paramsToMap(java.lang.String... params)
-
applyResourceLoader
<T> T applyResourceLoader(T factory) throws java.io.IOException- Throws:
java.io.IOException
-
-