Analysis: Allow to alias analyzers, closes #486.
This commit is contained in:
parent
171fa4a7e8
commit
e51523385d
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.elasticsearch.index.analysis;
|
package org.elasticsearch.index.analysis;
|
||||||
|
|
||||||
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.collect.ImmutableMap;
|
import org.elasticsearch.common.collect.ImmutableMap;
|
||||||
import org.elasticsearch.common.component.CloseableComponent;
|
import org.elasticsearch.common.component.CloseableComponent;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
|
@ -86,7 +87,18 @@ public class AnalysisService extends AbstractIndexComponent implements Closeable
|
||||||
|
|
||||||
Map<String, NamedAnalyzer> analyzers = newHashMap();
|
Map<String, NamedAnalyzer> analyzers = newHashMap();
|
||||||
for (AnalyzerProvider analyzerFactory : analyzerProviders.values()) {
|
for (AnalyzerProvider analyzerFactory : analyzerProviders.values()) {
|
||||||
analyzers.put(analyzerFactory.name(), new NamedAnalyzer(analyzerFactory.name(), analyzerFactory.scope(), analyzerFactory.get()));
|
NamedAnalyzer analyzer = new NamedAnalyzer(analyzerFactory.name(), analyzerFactory.scope(), analyzerFactory.get());
|
||||||
|
analyzers.put(analyzerFactory.name(), analyzer);
|
||||||
|
String strAliases = indexSettings.get("index.analysis.analyzer." + analyzerFactory.name() + ".alias");
|
||||||
|
if (strAliases != null) {
|
||||||
|
for (String alias : Strings.commaDelimitedListToStringArray(strAliases)) {
|
||||||
|
analyzers.put(alias, analyzer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String[] aliases = indexSettings.getAsArray("index.analysis.analyzer." + analyzerFactory.name() + ".alias");
|
||||||
|
for (String alias : aliases) {
|
||||||
|
analyzers.put(alias, analyzer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.analyzers = ImmutableMap.copyOf(analyzers);
|
this.analyzers = ImmutableMap.copyOf(analyzers);
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package org.elasticsearch.index.analysis;
|
package org.elasticsearch.index.analysis;
|
||||||
|
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
|
import org.apache.lucene.analysis.standard.StandardAnalyzer;
|
||||||
import org.elasticsearch.common.inject.Injector;
|
import org.elasticsearch.common.inject.Injector;
|
||||||
import org.elasticsearch.common.inject.ModulesBuilder;
|
import org.elasticsearch.common.inject.ModulesBuilder;
|
||||||
import org.elasticsearch.common.lucene.analysis.HTMLStripCharFilter;
|
import org.elasticsearch.common.lucene.analysis.HTMLStripCharFilter;
|
||||||
|
@ -77,5 +78,9 @@ public class AnalysisModuleTests {
|
||||||
|
|
||||||
html = (HtmlStripCharFilterFactory) custom2.charFilters()[1];
|
html = (HtmlStripCharFilterFactory) custom2.charFilters()[1];
|
||||||
assertThat(html.readAheadLimit(), equalTo(1024));
|
assertThat(html.readAheadLimit(), equalTo(1024));
|
||||||
|
|
||||||
|
// verify aliases
|
||||||
|
analyzer = analysisService.analyzer("alias1").analyzer();
|
||||||
|
assertThat(analyzer, instanceOf(StandardAnalyzer.class));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,10 +25,12 @@
|
||||||
},
|
},
|
||||||
"analyzer" : {
|
"analyzer" : {
|
||||||
"standard" : {
|
"standard" : {
|
||||||
|
"alias" : "alias1,alias2",
|
||||||
"type" : "standard",
|
"type" : "standard",
|
||||||
"stopwords" : ["test1", "test2", "test3"]
|
"stopwords" : ["test1", "test2", "test3"]
|
||||||
},
|
},
|
||||||
"custom1" : {
|
"custom1" : {
|
||||||
|
"alias" : ["alias4", "alias5"],
|
||||||
"tokenizer" : "standard",
|
"tokenizer" : "standard",
|
||||||
"filter" : ["stop", "stop2"]
|
"filter" : ["stop", "stop2"]
|
||||||
},
|
},
|
||||||
|
|
|
@ -17,9 +17,11 @@ index :
|
||||||
stopwords : [stop2-1, stop2-2]
|
stopwords : [stop2-1, stop2-2]
|
||||||
analyzer :
|
analyzer :
|
||||||
standard :
|
standard :
|
||||||
|
alias: alias1,alias2
|
||||||
type : standard
|
type : standard
|
||||||
stopwords : [test1, test2, test3]
|
stopwords : [test1, test2, test3]
|
||||||
custom1 :
|
custom1 :
|
||||||
|
alias : [alias4, alias5]
|
||||||
tokenizer : standard
|
tokenizer : standard
|
||||||
filter : [stop, stop2]
|
filter : [stop, stop2]
|
||||||
custom2 :
|
custom2 :
|
||||||
|
|
Loading…
Reference in New Issue