Skip to content

Commit 1c80ba0

Browse files
committed
clean-up
1 parent c28753c commit 1c80ba0

File tree

4 files changed

+14
-127
lines changed

4 files changed

+14
-127
lines changed

modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/CommonAnalysisPlugin.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@
114114
import org.elasticsearch.index.analysis.PreConfiguredTokenFilter;
115115
import org.elasticsearch.index.analysis.PreConfiguredTokenizer;
116116
import org.elasticsearch.index.analysis.StopRemoteWordListTokenFilterFactory;
117-
import org.elasticsearch.index.analysis.StopTokenFilterFactory;
118117
import org.elasticsearch.index.analysis.TokenFilterFactory;
119118
import org.elasticsearch.index.analysis.TokenizerFactory;
120119
import org.elasticsearch.index.analysis.WordListsIndexService;
@@ -331,9 +330,6 @@ public TokenStream create(TokenStream tokenStream) {
331330
filters.put("uppercase", UpperCaseTokenFilterFactory::new);
332331
filters.put("word_delimiter_graph", WordDelimiterGraphTokenFilterFactory::new);
333332
filters.put("word_delimiter", WordDelimiterTokenFilterFactory::new);
334-
filters.put("stop", requiresAnalysisSettings((i, e, n, s) -> new StopTokenFilterFactory(
335-
i, e, n, s, wordListsIndexServiceHolder.get()))
336-
);
337333
filters.put("stop_remote", requiresAnalysisSettings((i, e, n, s) -> new StopRemoteWordListTokenFilterFactory(
338334
i, e, n, s, wordListsIndexServiceHolder.get()))
339335
);

server/src/main/java/org/elasticsearch/index/analysis/Analysis.java

Lines changed: 11 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -187,31 +187,6 @@ public static CharArraySet parseWords(
187187
return defaultWords;
188188
}
189189

190-
// FIXME: Factor out this repeated code
191-
public static CharArraySet parseWords(
192-
Environment env,
193-
Settings settings,
194-
String name,
195-
CharArraySet defaultWords,
196-
Map<String, Set<?>> namedWords,
197-
boolean ignoreCase,
198-
WordListsIndexService wordListsIndexService
199-
) {
200-
String value = settings.get(name);
201-
if (value != null) {
202-
if ("_none_".equals(value)) {
203-
return CharArraySet.EMPTY_SET;
204-
} else {
205-
return resolveNamedWords(settings.getAsList(name), namedWords, ignoreCase);
206-
}
207-
}
208-
List<String> pathLoadedWords = getWordList(env, settings, name, wordListsIndexService);
209-
if (pathLoadedWords != null) {
210-
return resolveNamedWords(pathLoadedWords, namedWords, ignoreCase);
211-
}
212-
return defaultWords;
213-
}
214-
215190
public static CharArraySet parseCommonWords(Environment env, Settings settings, CharArraySet defaultCommonWords, boolean ignoreCase) {
216191
return parseWords(env, settings, "common_words", defaultCommonWords, NAMED_STOP_WORDS, ignoreCase);
217192
}
@@ -223,17 +198,11 @@ public static CharArraySet parseArticles(Environment env, Settings settings) {
223198

224199
public static CharArraySet parseStopWords(Environment env, Settings settings, CharArraySet defaultStopWords) {
225200
boolean stopwordsCase = settings.getAsBoolean("stopwords_case", false);
226-
return parseStopWords(env, settings, defaultStopWords, stopwordsCase, null);
201+
return parseStopWords(env, settings, defaultStopWords, stopwordsCase);
227202
}
228203

229-
public static CharArraySet parseStopWords(
230-
Environment env,
231-
Settings settings,
232-
CharArraySet defaultStopWords,
233-
boolean ignoreCase,
234-
WordListsIndexService wordListsIndexService
235-
) {
236-
return parseWords(env, settings, "stopwords", defaultStopWords, NAMED_STOP_WORDS, ignoreCase, wordListsIndexService);
204+
public static CharArraySet parseStopWords(Environment env, Settings settings, CharArraySet defaultStopWords, boolean ignoreCase) {
205+
return parseWords(env, settings, "stopwords", defaultStopWords, NAMED_STOP_WORDS, ignoreCase);
237206
}
238207

239208
private static CharArraySet resolveNamedWords(Collection<String> words, Map<String, Set<?>> namedWords, boolean ignoreCase) {
@@ -268,17 +237,7 @@ public static CharArraySet getWordSet(Environment env, Settings settings, String
268237
* If the word list cannot be found at either key.
269238
*/
270239
public static List<String> getWordList(Environment env, Settings settings, String settingPrefix) {
271-
return getWordList(env, settings, settingPrefix + "_path", settingPrefix, true, null);
272-
}
273-
274-
// FIXME: Factor out this repeated code
275-
public static List<String> getWordList(
276-
Environment env,
277-
Settings settings,
278-
String settingPrefix,
279-
WordListsIndexService wordListsIndexService
280-
) {
281-
return getWordList(env, settings, settingPrefix + "_path", settingPrefix, true, wordListsIndexService);
240+
return getWordList(env, settings, settingPrefix + "_path", settingPrefix, true);
282241
}
283242

284243
/**
@@ -293,8 +252,7 @@ public static List<String> getWordList(
293252
Settings settings,
294253
String settingPath,
295254
String settingList,
296-
boolean removeComments,
297-
WordListsIndexService wordListIndexService
255+
boolean removeComments
298256
) {
299257
String wordListPath = settings.get(settingPath, null);
300258

@@ -307,84 +265,22 @@ public static List<String> getWordList(
307265
}
308266
}
309267

310-
// final URI pathAsUri = tryToParsePathAsUri(wordListPath);
311-
// final Path path;
312-
// final boolean deletePath;
313-
// if (pathAsUri != null) {
314-
// try {
315-
// path = downloadFile(pathAsUri);
316-
// deletePath = true;
317-
// } catch (IOException e) {
318-
// String message = Strings.format("IOException while downloading file %s", settingPath);
319-
// throw new IllegalArgumentException(message, e);
320-
// } catch (InterruptedException e) {
321-
// Thread.currentThread().interrupt();
322-
// String message = Strings.format("InterruptedException while downloading file %s", settingPath);
323-
// throw new IllegalArgumentException(message, e);
324-
// }
325-
// } else {
326-
// path = env.configFile().resolve(wordListPath);
327-
// deletePath = false;
328-
// }
329-
330-
final URL pathAsUrl = tryToParsePathAsURL(wordListPath);
331-
String stringValue = null;
332-
Path pathValue = null;
333-
if (pathAsUrl != null) {
334-
// TODO: Don't hard-code index name
335-
final String fakeIndexName = "hard-coded-index";
336-
PlainActionFuture<String> wordListLoadingFuture = new PlainActionFuture<>();
337-
wordListIndexService.getWordListValue(fakeIndexName, wordListPath, wordListLoadingFuture);
338-
339-
stringValue = wordListLoadingFuture.actionGet();
340-
boolean writeStringValue = false;
341-
if (stringValue == null) {
342-
try {
343-
stringValue = readFile(pathAsUrl);
344-
} catch (IOException e) {
345-
String message = Strings.format("IOException while reading file at %s", settingPath);
346-
throw new IllegalArgumentException(message, e);
347-
}
348-
349-
writeStringValue = true;
350-
}
351-
352-
if (writeStringValue) {
353-
wordListIndexService.putWordList(fakeIndexName, wordListPath, stringValue, new ActionListener<>() {
354-
@Override
355-
public void onResponse(WordListsIndexService.PutWordListResult putWordListResult) {
356-
// TODO: Log result
357-
}
358-
359-
@Override
360-
public void onFailure(Exception e) {
361-
throw new ElasticsearchStatusException(
362-
"Unable to index word list [" + wordListPath + "] for index [" + fakeIndexName + "]",
363-
RestStatus.INTERNAL_SERVER_ERROR,
364-
e
365-
);
366-
}
367-
});
368-
}
369-
} else {
370-
pathValue = env.configFile().resolve(wordListPath);
371-
}
268+
final Path path = env.configFile().resolve(wordListPath);
372269

373270
try {
374-
// TODO: Clean up error handling
375-
return stringValue != null ? loadWordList(stringValue, removeComments) : loadWordList(pathValue, removeComments);
271+
return loadWordList(path, removeComments);
376272
} catch (CharacterCodingException ex) {
377273
String message = Strings.format(
378274
"Unsupported character encoding detected while reading %s: %s - files must be UTF-8 encoded",
379275
settingPath,
380-
pathValue
276+
path
381277
);
382278
throw new IllegalArgumentException(message, ex);
383279
} catch (IOException ioe) {
384-
String message = Strings.format("IOException while reading %s: %s", settingPath, pathValue);
280+
String message = Strings.format("IOException while reading %s: %s", settingPath, path);
385281
throw new IllegalArgumentException(message, ioe);
386282
} catch (AccessControlException ace) {
387-
throw new IllegalArgumentException(Strings.format("Access denied trying to read file %s: %s", settingPath, pathValue), ace);
283+
throw new IllegalArgumentException(Strings.format("Access denied trying to read file %s: %s", settingPath, path), ace);
388284
}
389285
}
390286

@@ -494,7 +390,7 @@ public static List<String> getWordList(
494390
boolean removeComments,
495391
boolean checkDuplicate
496392
) {
497-
final List<String> ruleList = getWordList(env, settings, settingPath, settingList, removeComments, null);
393+
final List<String> ruleList = getWordList(env, settings, settingPath, settingList, removeComments);
498394
if (ruleList != null && ruleList.isEmpty() == false && checkDuplicate) {
499395
checkDuplicateRules(ruleList);
500396
}

server/src/main/java/org/elasticsearch/index/analysis/StopTokenFilterFactory.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,11 @@ public class StopTokenFilterFactory extends AbstractTokenFilterFactory {
2727

2828
private final boolean removeTrailing;
2929

30-
public StopTokenFilterFactory(
31-
IndexSettings indexSettings,
32-
Environment env,
33-
String name,
34-
Settings settings,
35-
WordListsIndexService wordListsIndexService
36-
) {
30+
public StopTokenFilterFactory(IndexSettings indexSettings, Environment env, String name, Settings settings) {
3731
super(name, settings);
3832
this.ignoreCase = settings.getAsBoolean("ignore_case", false);
3933
this.removeTrailing = settings.getAsBoolean("remove_trailing", true);
40-
this.stopWords = Analysis.parseStopWords(env, settings, EnglishAnalyzer.ENGLISH_STOP_WORDS_SET, ignoreCase, wordListsIndexService);
34+
this.stopWords = Analysis.parseStopWords(env, settings, EnglishAnalyzer.ENGLISH_STOP_WORDS_SET, ignoreCase);
4135
if (settings.get("enable_position_increments") != null) {
4236
throw new IllegalArgumentException("enable_position_increments is not supported anymore. Please fix your analysis chain");
4337
}

server/src/main/java/org/elasticsearch/indices/analysis/AnalysisModule.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ private static NamedRegistry<AnalysisProvider<TokenFilterFactory>> setupTokenFil
132132
StablePluginsRegistry stablePluginRegistry
133133
) {
134134
NamedRegistry<AnalysisProvider<TokenFilterFactory>> tokenFilters = new NamedRegistry<>("token_filter");
135+
tokenFilters.register("stop", StopTokenFilterFactory::new);
135136
// Add "standard" for old indices (bwc)
136137
tokenFilters.register("standard", new AnalysisProvider<TokenFilterFactory>() {
137138
@Override

0 commit comments

Comments
 (0)