Analysis: Regression (0.16.1), Camel cased filters / tokenizers failed to load in custom analyzer, closes #937.
This commit is contained in:
parent
518488b0b2
commit
af222dc75c
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.elasticsearch.index.analysis;
|
package org.elasticsearch.index.analysis;
|
||||||
|
|
||||||
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.inject.assistedinject.Assisted;
|
import org.elasticsearch.common.inject.assistedinject.Assisted;
|
||||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
|
@ -39,12 +40,6 @@ import static org.elasticsearch.common.collect.Lists.*;
|
||||||
*/
|
*/
|
||||||
public class CustomAnalyzerProvider extends AbstractIndexAnalyzerProvider<CustomAnalyzer> {
|
public class CustomAnalyzerProvider extends AbstractIndexAnalyzerProvider<CustomAnalyzer> {
|
||||||
|
|
||||||
private final TokenizerFactory tokenizerFactory;
|
|
||||||
|
|
||||||
private final CharFilterFactory[] charFilterFactories;
|
|
||||||
|
|
||||||
private final TokenFilterFactory[] tokenFilterFactories;
|
|
||||||
|
|
||||||
private final CustomAnalyzer customAnalyzer;
|
private final CustomAnalyzer customAnalyzer;
|
||||||
|
|
||||||
@Inject public CustomAnalyzerProvider(Index index,
|
@Inject public CustomAnalyzerProvider(Index index,
|
||||||
|
@ -59,46 +54,64 @@ public class CustomAnalyzerProvider extends AbstractIndexAnalyzerProvider<Custom
|
||||||
throw new IllegalArgumentException("Custom Analyzer [" + name + "] must be configured with a tokenizer");
|
throw new IllegalArgumentException("Custom Analyzer [" + name + "] must be configured with a tokenizer");
|
||||||
}
|
}
|
||||||
TokenizerFactoryFactory tokenizerFactoryFactory = tokenizerFactories.get(tokenizerName);
|
TokenizerFactoryFactory tokenizerFactoryFactory = tokenizerFactories.get(tokenizerName);
|
||||||
|
if (tokenizerFactoryFactory == null) {
|
||||||
|
tokenizerFactoryFactory = tokenizerFactories.get(Strings.toCamelCase(tokenizerName));
|
||||||
|
if (tokenizerFactoryFactory == null) {
|
||||||
|
tokenizerFactoryFactory = tokenizerFactories.get(Strings.toUnderscoreCase(tokenizerName));
|
||||||
if (tokenizerFactoryFactory == null) {
|
if (tokenizerFactoryFactory == null) {
|
||||||
throw new IllegalArgumentException("Custom Analyzer [" + name + "] failed to find tokenizer under name [" + tokenizerName + "]");
|
throw new IllegalArgumentException("Custom Analyzer [" + name + "] failed to find tokenizer under name [" + tokenizerName + "]");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Settings tokenizerSettings = indexSettings.getGroups("index.analysis.tokenizer").get(tokenizerName);
|
Settings tokenizerSettings = indexSettings.getGroups("index.analysis.tokenizer").get(tokenizerName);
|
||||||
if (tokenizerSettings == null) {
|
if (tokenizerSettings == null) {
|
||||||
tokenizerSettings = ImmutableSettings.Builder.EMPTY_SETTINGS;
|
tokenizerSettings = ImmutableSettings.Builder.EMPTY_SETTINGS;
|
||||||
}
|
}
|
||||||
tokenizerFactory = tokenizerFactoryFactory.create(tokenizerName, tokenizerSettings);
|
TokenizerFactory tokenizerFactory = tokenizerFactoryFactory.create(tokenizerName, tokenizerSettings);
|
||||||
|
|
||||||
List<CharFilterFactory> charFilters = newArrayList();
|
List<CharFilterFactory> charFilters = newArrayList();
|
||||||
String[] charFilterNames = settings.getAsArray("char_filter");
|
String[] charFilterNames = settings.getAsArray("char_filter");
|
||||||
for (String charFilterName : charFilterNames) {
|
for (String charFilterName : charFilterNames) {
|
||||||
CharFilterFactoryFactory charFilterFactoryFactory = charFilterFactories.get(charFilterName);
|
CharFilterFactoryFactory charFilterFactoryFactory = charFilterFactories.get(charFilterName);
|
||||||
|
if (charFilterFactoryFactory == null) {
|
||||||
|
charFilterFactoryFactory = charFilterFactories.get(Strings.toCamelCase(charFilterName));
|
||||||
|
if (charFilterFactoryFactory == null) {
|
||||||
|
charFilterFactoryFactory = charFilterFactories.get(Strings.toUnderscoreCase(charFilterName));
|
||||||
if (charFilterFactoryFactory == null) {
|
if (charFilterFactoryFactory == null) {
|
||||||
throw new IllegalArgumentException("Custom Analyzer [" + name + "] failed to find char filter under name [" + charFilterName + "]");
|
throw new IllegalArgumentException("Custom Analyzer [" + name + "] failed to find char filter under name [" + charFilterName + "]");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Settings charFilterSettings = indexSettings.getGroups("index.analysis.char_filter").get(charFilterName);
|
Settings charFilterSettings = indexSettings.getGroups("index.analysis.char_filter").get(charFilterName);
|
||||||
if (charFilterSettings == null) {
|
if (charFilterSettings == null) {
|
||||||
charFilterSettings = ImmutableSettings.Builder.EMPTY_SETTINGS;
|
charFilterSettings = ImmutableSettings.Builder.EMPTY_SETTINGS;
|
||||||
}
|
}
|
||||||
charFilters.add(charFilterFactoryFactory.create(charFilterName, charFilterSettings));
|
charFilters.add(charFilterFactoryFactory.create(charFilterName, charFilterSettings));
|
||||||
}
|
}
|
||||||
this.charFilterFactories = charFilters.toArray(new CharFilterFactory[charFilters.size()]);
|
CharFilterFactory[] charFilterFactories1 = charFilters.toArray(new CharFilterFactory[charFilters.size()]);
|
||||||
|
|
||||||
List<TokenFilterFactory> tokenFilters = newArrayList();
|
List<TokenFilterFactory> tokenFilters = newArrayList();
|
||||||
String[] tokenFilterNames = settings.getAsArray("filter");
|
String[] tokenFilterNames = settings.getAsArray("filter");
|
||||||
for (String tokenFilterName : tokenFilterNames) {
|
for (String tokenFilterName : tokenFilterNames) {
|
||||||
TokenFilterFactoryFactory tokenFilterFactoryFactory = tokenFilterFactories.get(tokenFilterName);
|
TokenFilterFactoryFactory tokenFilterFactoryFactory = tokenFilterFactories.get(tokenFilterName);
|
||||||
|
if (tokenFilterFactoryFactory == null) {
|
||||||
|
tokenFilterFactoryFactory = tokenFilterFactories.get(Strings.toCamelCase(tokenFilterName));
|
||||||
|
if (tokenFilterFactoryFactory == null) {
|
||||||
|
tokenFilterFactoryFactory = tokenFilterFactories.get(Strings.toUnderscoreCase(tokenFilterName));
|
||||||
if (tokenFilterFactoryFactory == null) {
|
if (tokenFilterFactoryFactory == null) {
|
||||||
throw new IllegalArgumentException("Custom Analyzer [" + name + "] failed to find token filter under name [" + tokenFilterName + "]");
|
throw new IllegalArgumentException("Custom Analyzer [" + name + "] failed to find token filter under name [" + tokenFilterName + "]");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Settings tokenFilterSettings = indexSettings.getGroups("index.analysis.filter").get(tokenFilterName);
|
Settings tokenFilterSettings = indexSettings.getGroups("index.analysis.filter").get(tokenFilterName);
|
||||||
if (tokenFilterSettings == null) {
|
if (tokenFilterSettings == null) {
|
||||||
tokenFilterSettings = ImmutableSettings.Builder.EMPTY_SETTINGS;
|
tokenFilterSettings = ImmutableSettings.Builder.EMPTY_SETTINGS;
|
||||||
}
|
}
|
||||||
tokenFilters.add(tokenFilterFactoryFactory.create(tokenFilterName, tokenFilterSettings));
|
tokenFilters.add(tokenFilterFactoryFactory.create(tokenFilterName, tokenFilterSettings));
|
||||||
}
|
}
|
||||||
this.tokenFilterFactories = tokenFilters.toArray(new TokenFilterFactory[tokenFilters.size()]);
|
TokenFilterFactory[] tokenFilterFactories1 = tokenFilters.toArray(new TokenFilterFactory[tokenFilters.size()]);
|
||||||
|
|
||||||
this.customAnalyzer = new CustomAnalyzer(this.tokenizerFactory, this.charFilterFactories, this.tokenFilterFactories);
|
this.customAnalyzer = new CustomAnalyzer(tokenizerFactory, charFilterFactories1, tokenFilterFactories1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public CustomAnalyzer get() {
|
@Override public CustomAnalyzer get() {
|
||||||
|
|
Loading…
Reference in New Issue