diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/Analysis.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/Analysis.java index 08ab255d8ac..cb9156c936f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/Analysis.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/Analysis.java @@ -119,7 +119,7 @@ public class Analysis { .put("_turkish_", TurkishAnalyzer.getDefaultStopSet()) .immutableMap(); - public static Set parseStopWords(Settings settings, Set defaultStopWords) { + public static Set parseStopWords(Environment env, Settings settings, Set defaultStopWords) { String value = settings.get("stopwords"); if (value != null) { if ("_none_".equals(value)) { @@ -139,9 +139,21 @@ public class Analysis { } } return setStopWords; - } else { - return defaultStopWords; } + Set pathLoadedStopWords = getWordList(env, settings, "stopwords"); + if (pathLoadedStopWords != null) { + Set setStopWords = new HashSet(); + for (String stopWord : pathLoadedStopWords) { + if (namedStopWords.containsKey(stopWord)) { + setStopWords.addAll(namedStopWords.get(stopWord)); + } else { + setStopWords.add(stopWord); + } + } + return setStopWords; + } + + return defaultStopWords; } /** diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/AnalysisService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/AnalysisService.java index 7b75fa43d27..ef50c727f1f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/AnalysisService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/AnalysisService.java @@ -76,7 +76,7 @@ public class AnalysisService extends AbstractIndexComponent implements Closeable } if (!analyzerProviders.containsKey("default")) { - analyzerProviders.put("default", new StandardAnalyzerProvider(index, indexSettings, "default", ImmutableSettings.Builder.EMPTY_SETTINGS)); + analyzerProviders.put("default", new StandardAnalyzerProvider(index, indexSettings, null, "default", ImmutableSettings.Builder.EMPTY_SETTINGS)); } if (!analyzerProviders.containsKey("default_index")) { analyzerProviders.put("default_index", analyzerProviders.get("default")); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/ArabicAnalyzerProvider.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/ArabicAnalyzerProvider.java index 5b7f4e83748..61c8baf113f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/ArabicAnalyzerProvider.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/ArabicAnalyzerProvider.java @@ -24,6 +24,7 @@ import org.apache.lucene.analysis.ar.ArabicAnalyzer; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.env.Environment; import org.elasticsearch.index.Index; import org.elasticsearch.index.settings.IndexSettings; @@ -34,10 +35,10 @@ public class ArabicAnalyzerProvider extends AbstractIndexAnalyzerProvider stopWords = Analysis.parseStopWords(settings, CJKAnalyzer.getDefaultStopSet()); + Set stopWords = Analysis.parseStopWords(env, settings, CJKAnalyzer.getDefaultStopSet()); analyzer = new CJKAnalyzer(version, stopWords); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/CzechAnalyzerProvider.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/CzechAnalyzerProvider.java index 6a9d0bc7ed0..5c60c7624ce 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/CzechAnalyzerProvider.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/CzechAnalyzerProvider.java @@ -24,6 +24,7 @@ import org.apache.lucene.analysis.cz.CzechAnalyzer; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.env.Environment; import org.elasticsearch.index.Index; import org.elasticsearch.index.settings.IndexSettings; @@ -34,10 +35,10 @@ public class CzechAnalyzerProvider extends AbstractIndexAnalyzerProvider stopWords = Analysis.parseStopWords(settings, StopAnalyzer.ENGLISH_STOP_WORDS_SET); + Set stopWords = Analysis.parseStopWords(env, settings, StopAnalyzer.ENGLISH_STOP_WORDS_SET); String sPattern = settings.get("pattern", "\\W+" /*PatternAnalyzer.NON_WORD_PATTERN*/); if (sPattern == null) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/PersianAnalyzerProvider.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/PersianAnalyzerProvider.java index 87774ef8488..00fcffd884d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/PersianAnalyzerProvider.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/PersianAnalyzerProvider.java @@ -23,6 +23,7 @@ import org.apache.lucene.analysis.fa.PersianAnalyzer; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.env.Environment; import org.elasticsearch.index.Index; import org.elasticsearch.index.settings.IndexSettings; @@ -33,10 +34,10 @@ public class PersianAnalyzerProvider extends AbstractIndexAnalyzerProvider defaultStopwords = defaultLanguageStopwords.containsKey(language) ? defaultLanguageStopwords.get(language) : ImmutableSet.>of(); - Set stopWords = Analysis.parseStopWords(settings, defaultStopwords); + Set stopWords = Analysis.parseStopWords(env, settings, defaultStopwords); analyzer = new SnowballAnalyzer(version, language, stopWords); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/SpanishAnalyzerProvider.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/SpanishAnalyzerProvider.java index ca46c4b1890..89dad463960 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/SpanishAnalyzerProvider.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/SpanishAnalyzerProvider.java @@ -24,6 +24,7 @@ import org.apache.lucene.analysis.es.SpanishAnalyzer; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.env.Environment; import org.elasticsearch.index.Index; import org.elasticsearch.index.settings.IndexSettings; @@ -34,10 +35,10 @@ public class SpanishAnalyzerProvider extends AbstractIndexAnalyzerProvider stopWords = Analysis.parseStopWords(settings, StopAnalyzer.ENGLISH_STOP_WORDS_SET); + Set stopWords = Analysis.parseStopWords(env, settings, StopAnalyzer.ENGLISH_STOP_WORDS_SET); int maxTokenLength = settings.getAsInt("max_token_length", StandardAnalyzer.DEFAULT_MAX_TOKEN_LENGTH); standardAnalyzer = new StandardAnalyzer(version, stopWords); standardAnalyzer.setMaxTokenLength(maxTokenLength); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/StopAnalyzerProvider.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/StopAnalyzerProvider.java index 49df0c7e81d..eebd5da9077 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/StopAnalyzerProvider.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/StopAnalyzerProvider.java @@ -23,6 +23,7 @@ import org.apache.lucene.analysis.StopAnalyzer; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.env.Environment; import org.elasticsearch.index.Index; import org.elasticsearch.index.settings.IndexSettings; @@ -35,9 +36,9 @@ public class StopAnalyzerProvider extends AbstractIndexAnalyzerProvider stopWords = Analysis.parseStopWords(settings, StopAnalyzer.ENGLISH_STOP_WORDS_SET); + Set stopWords = Analysis.parseStopWords(env, settings, StopAnalyzer.ENGLISH_STOP_WORDS_SET); this.stopAnalyzer = new StopAnalyzer(version, stopWords); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/StopTokenFilterFactory.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/StopTokenFilterFactory.java index 2de535b7fee..f43a571c729 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/StopTokenFilterFactory.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/StopTokenFilterFactory.java @@ -25,6 +25,7 @@ import org.apache.lucene.analysis.TokenStream; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.env.Environment; import org.elasticsearch.index.Index; import org.elasticsearch.index.settings.IndexSettings; @@ -39,9 +40,9 @@ public class StopTokenFilterFactory extends AbstractTokenFilterFactory { private final boolean ignoreCase; - @Inject public StopTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, @Assisted String name, @Assisted Settings settings) { + @Inject public StopTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, Environment env, @Assisted String name, @Assisted Settings settings) { super(index, indexSettings, name, settings); - this.stopWords = Analysis.parseStopWords(settings, StopAnalyzer.ENGLISH_STOP_WORDS_SET); + this.stopWords = Analysis.parseStopWords(env, settings, StopAnalyzer.ENGLISH_STOP_WORDS_SET); this.ignoreCase = settings.getAsBoolean("ignore_case", false); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/SwedishAnalyzerProvider.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/SwedishAnalyzerProvider.java index a4a183e9005..159a215b1e1 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/SwedishAnalyzerProvider.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/SwedishAnalyzerProvider.java @@ -24,6 +24,7 @@ import org.apache.lucene.analysis.sv.SwedishAnalyzer; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.env.Environment; import org.elasticsearch.index.Index; import org.elasticsearch.index.settings.IndexSettings; @@ -34,10 +35,10 @@ public class SwedishAnalyzerProvider extends AbstractIndexAnalyzerProvider