Analysis: Allow to alias analyzers, closes #486.

This commit is contained in:
kimchy 2010-11-07 20:10:53 +02:00
parent 171fa4a7e8
commit e51523385d
4 changed files with 22 additions and 1 deletions

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.analysis;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.ImmutableMap;
import org.elasticsearch.common.component.CloseableComponent;
import org.elasticsearch.common.inject.Inject;
@ -86,7 +87,18 @@ public class AnalysisService extends AbstractIndexComponent implements Closeable
Map<String, NamedAnalyzer> analyzers = newHashMap();
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);

View File

@ -20,6 +20,7 @@
package org.elasticsearch.index.analysis;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.inject.ModulesBuilder;
import org.elasticsearch.common.lucene.analysis.HTMLStripCharFilter;
@ -77,5 +78,9 @@ public class AnalysisModuleTests {
html = (HtmlStripCharFilterFactory) custom2.charFilters()[1];
assertThat(html.readAheadLimit(), equalTo(1024));
// verify aliases
analyzer = analysisService.analyzer("alias1").analyzer();
assertThat(analyzer, instanceOf(StandardAnalyzer.class));
}
}

View File

@ -25,10 +25,12 @@
},
"analyzer" : {
"standard" : {
"alias" : "alias1,alias2",
"type" : "standard",
"stopwords" : ["test1", "test2", "test3"]
},
"custom1" : {
"alias" : ["alias4", "alias5"],
"tokenizer" : "standard",
"filter" : ["stop", "stop2"]
},

View File

@ -17,9 +17,11 @@ index :
stopwords : [stop2-1, stop2-2]
analyzer :
standard :
alias: alias1,alias2
type : standard
stopwords : [test1, test2, test3]
custom1 :
alias : [alias4, alias5]
tokenizer : standard
filter : [stop, stop2]
custom2 :