@@ -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 }
0 commit comments