better failure when missing default analyzer, don't allow to override name method with extending index analyzer, always use the injected one

This commit is contained in:
Shay Banon 2012-05-20 12:24:14 +02:00
parent 65ae606c41
commit 090fefe05c
2 changed files with 15 additions and 3 deletions

View File

@ -63,13 +63,16 @@ public abstract class AbstractIndexAnalyzerProvider<T extends Analyzer> extends
this.version = Lucene.parseVersion(settings.get("version"), Lucene.ANALYZER_VERSION, logger); this.version = Lucene.parseVersion(settings.get("version"), Lucene.ANALYZER_VERSION, logger);
} }
/**
* Returns the injected name of the analyzer.
*/
@Override @Override
public String name() { public final String name() {
return this.name; return this.name;
} }
@Override @Override
public AnalyzerScope scope() { public final AnalyzerScope scope() {
return AnalyzerScope.INDEX; return AnalyzerScope.INDEX;
} }
} }

View File

@ -20,6 +20,8 @@
package org.elasticsearch.index.analysis; package org.elasticsearch.index.analysis;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import org.apache.lucene.analysis.Analyzer;
import org.elasticsearch.ElasticSearchIllegalArgumentException;
import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.component.CloseableComponent; import org.elasticsearch.common.component.CloseableComponent;
@ -219,7 +221,11 @@ public class AnalysisService extends AbstractIndexComponent implements Closeable
if (analyzerFactory instanceof CustomAnalyzerProvider) { if (analyzerFactory instanceof CustomAnalyzerProvider) {
((CustomAnalyzerProvider) analyzerFactory).build(this); ((CustomAnalyzerProvider) analyzerFactory).build(this);
} }
NamedAnalyzer analyzer = new NamedAnalyzer(analyzerFactory.name(), analyzerFactory.scope(), analyzerFactory.get()); Analyzer analyzerF = analyzerFactory.get();
if (analyzerF == null) {
throw new ElasticSearchIllegalArgumentException("analyzer [" + analyzerFactory.name() + "] created null analyzer");
}
NamedAnalyzer analyzer = new NamedAnalyzer(analyzerFactory.name(), analyzerFactory.scope(), analyzerF);
analyzers.put(analyzerFactory.name(), analyzer); analyzers.put(analyzerFactory.name(), analyzer);
analyzers.put(Strings.toCamelCase(analyzerFactory.name()), analyzer); analyzers.put(Strings.toCamelCase(analyzerFactory.name()), analyzer);
String strAliases = indexSettings.get("index.analysis.analyzer." + analyzerFactory.name() + ".alias"); String strAliases = indexSettings.get("index.analysis.analyzer." + analyzerFactory.name() + ".alias");
@ -235,6 +241,9 @@ public class AnalysisService extends AbstractIndexComponent implements Closeable
} }
defaultAnalyzer = analyzers.get("default"); defaultAnalyzer = analyzers.get("default");
if (defaultAnalyzer == null) {
throw new ElasticSearchIllegalArgumentException("no default analyzer configured");
}
defaultIndexAnalyzer = analyzers.containsKey("default_index") ? analyzers.get("default_index") : analyzers.get("default"); defaultIndexAnalyzer = analyzers.containsKey("default_index") ? analyzers.get("default_index") : analyzers.get("default");
defaultSearchAnalyzer = analyzers.containsKey("default_search") ? analyzers.get("default_search") : analyzers.get("default"); defaultSearchAnalyzer = analyzers.containsKey("default_search") ? analyzers.get("default_search") : analyzers.get("default");
defaultSearchQuoteAnalyzer = analyzers.containsKey("default_search_quote") ? analyzers.get("default_search_quote") : defaultSearchAnalyzer; defaultSearchQuoteAnalyzer = analyzers.containsKey("default_search_quote") ? analyzers.get("default_search_quote") : defaultSearchAnalyzer;