From af222dc75c2736d9de79ea7f376f0606f8a02305 Mon Sep 17 00:00:00 2001 From: kimchy Date: Tue, 17 May 2011 14:20:32 +0300 Subject: [PATCH] Analysis: Regression (0.16.1), Camel cased filters / tokenizers failed to load in custom analyzer, closes #937. --- .../analysis/CustomAnalyzerProvider.java | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/CustomAnalyzerProvider.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/CustomAnalyzerProvider.java index 24caeceb88f..56548c66b53 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/CustomAnalyzerProvider.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/CustomAnalyzerProvider.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.analysis; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.ImmutableSettings; @@ -39,12 +40,6 @@ import static org.elasticsearch.common.collect.Lists.*; */ public class CustomAnalyzerProvider extends AbstractIndexAnalyzerProvider { - private final TokenizerFactory tokenizerFactory; - - private final CharFilterFactory[] charFilterFactories; - - private final TokenFilterFactory[] tokenFilterFactories; - private final CustomAnalyzer customAnalyzer; @Inject public CustomAnalyzerProvider(Index index, @@ -60,20 +55,32 @@ public class CustomAnalyzerProvider extends AbstractIndexAnalyzerProvider charFilters = newArrayList(); String[] charFilterNames = settings.getAsArray("char_filter"); for (String charFilterName : charFilterNames) { CharFilterFactoryFactory charFilterFactoryFactory = charFilterFactories.get(charFilterName); if (charFilterFactoryFactory == null) { - throw new IllegalArgumentException("Custom Analyzer [" + name + "] failed to find char filter under name [" + charFilterName + "]"); + charFilterFactoryFactory = charFilterFactories.get(Strings.toCamelCase(charFilterName)); + if (charFilterFactoryFactory == null) { + charFilterFactoryFactory = charFilterFactories.get(Strings.toUnderscoreCase(charFilterName)); + if (charFilterFactoryFactory == null) { + throw new IllegalArgumentException("Custom Analyzer [" + name + "] failed to find char filter under name [" + charFilterName + "]"); + } + } } Settings charFilterSettings = indexSettings.getGroups("index.analysis.char_filter").get(charFilterName); if (charFilterSettings == null) { @@ -81,14 +88,20 @@ public class CustomAnalyzerProvider extends AbstractIndexAnalyzerProvider tokenFilters = newArrayList(); String[] tokenFilterNames = settings.getAsArray("filter"); for (String tokenFilterName : tokenFilterNames) { TokenFilterFactoryFactory tokenFilterFactoryFactory = tokenFilterFactories.get(tokenFilterName); if (tokenFilterFactoryFactory == null) { - throw new IllegalArgumentException("Custom Analyzer [" + name + "] failed to find token filter under name [" + tokenFilterName + "]"); + tokenFilterFactoryFactory = tokenFilterFactories.get(Strings.toCamelCase(tokenFilterName)); + if (tokenFilterFactoryFactory == null) { + tokenFilterFactoryFactory = tokenFilterFactories.get(Strings.toUnderscoreCase(tokenFilterName)); + if (tokenFilterFactoryFactory == null) { + throw new IllegalArgumentException("Custom Analyzer [" + name + "] failed to find token filter under name [" + tokenFilterName + "]"); + } + } } Settings tokenFilterSettings = indexSettings.getGroups("index.analysis.filter").get(tokenFilterName); if (tokenFilterSettings == null) { @@ -96,9 +109,9 @@ public class CustomAnalyzerProvider extends AbstractIndexAnalyzerProvider