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:
parent
65ae606c41
commit
090fefe05c
|
@ -63,13 +63,16 @@ public abstract class AbstractIndexAnalyzerProvider<T extends Analyzer> extends
|
|||
this.version = Lucene.parseVersion(settings.get("version"), Lucene.ANALYZER_VERSION, logger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the injected name of the analyzer.
|
||||
*/
|
||||
@Override
|
||||
public String name() {
|
||||
public final String name() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnalyzerScope scope() {
|
||||
public final AnalyzerScope scope() {
|
||||
return AnalyzerScope.INDEX;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
package org.elasticsearch.index.analysis;
|
||||
|
||||
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.Strings;
|
||||
import org.elasticsearch.common.component.CloseableComponent;
|
||||
|
@ -219,7 +221,11 @@ public class AnalysisService extends AbstractIndexComponent implements Closeable
|
|||
if (analyzerFactory instanceof CustomAnalyzerProvider) {
|
||||
((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(Strings.toCamelCase(analyzerFactory.name()), analyzer);
|
||||
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");
|
||||
if (defaultAnalyzer == null) {
|
||||
throw new ElasticSearchIllegalArgumentException("no default analyzer configured");
|
||||
}
|
||||
defaultIndexAnalyzer = analyzers.containsKey("default_index") ? analyzers.get("default_index") : 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;
|
||||
|
|
Loading…
Reference in New Issue