package org.codelibs.elasticsearch.ja.analysis;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Set;

import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.util.WordlistLoader;
import org.codelibs.analysis.ja.PosConcatenationFilter;
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.analysis.AbstractTokenFilterFactory;
import org.elasticsearch.index.settings.IndexSettingsService;

public class PosConcatenationFilterFactory extends AbstractTokenFilterFactory {

    private Set<String> posTags;

    @Inject
    public PosConcatenationFilterFactory(Index index, IndexSettingsService indexSettingsService, @Assisted String name,
            @Assisted Settings settings, Environment env) {
        super(index, indexSettingsService.getSettings(), name, settings);

        String posPath = settings.get("tags_path");

        if (posPath != null) {
            File posFile = env.configFile().resolve(posPath).toFile();
            try (InputStream is = new FileInputStream(posFile)) {
                posTags.addAll(WordlistLoader.getLines(is, StandardCharsets.UTF_8));
            } catch (IOException e) {
                throw new IllegalArgumentException("Could not load " + posFile.getAbsolutePath(), e);
            }
        } else {
            String tags = settings.get("tags");
            if (tags != null) {
                for (String tag : tags.split(",")) {
                    posTags.add(tag.trim());
                }
            } else {
                posTags = new HashSet<>();
            }
        }
    }

    @Override
    public TokenStream create(TokenStream tokenStream) {
        return new PosConcatenationFilter(tokenStream, posTags);
    }
}

@@ -58,145 +58,20 @@
 ava.
-io.File;%0Aimport java.io.FileInputStream;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.nio.charset.StandardChars
+util.HashS
 et
-s
 ;%0Aim
@@ -77,38 +77,35 @@
 mport java.util.
-HashSe
+Lis
 t;%0Aimport java.u
@@ -165,63 +165,8 @@
 am;%0A
-import org.apache.lucene.analysis.util.WordlistLoader;%0A
 impo
@@ -527,16 +527,66 @@
 actory;%0A
+import org.elasticsearch.index.analysis.Analysis;%0A
 import o
@@ -752,16 +752,34 @@
  posTags
+ = new HashSet%3C%3E()
 ;%0A%0A    @
@@ -1052,516 +1052,67 @@
     
+List%3C
 String
- posPath = settings.get(%22tags_path%22);%0A%0A        if (posPath != null) %7B%0A            File posFile = env.configFile().resolve(posPath).toFile();%0A            try (InputStream is = new FileInputStream(posFile)) %7B%0A                posTags.addAll(
+%3E tagList = Analysis.get
 Word
-listLoader.getLines(is, StandardCharsets.UTF_8));%0A            %7D catch (IOException e) %7B%0A                throw new IllegalArgumentException(%22Could not load %22 + posFile.getAbsolutePath(), e);%0A            %7D%0A        %7D else %7B%0A            String tags = settings.get(
+List(env, settings, 
 %22tag
@@ -1128,20 +1128,19 @@
     
-    
 if (tag
-s
+List
  != 
@@ -1151,69 +1151,8 @@
 ) %7B%0A
-                for (String tag : tags.split(%22,%22)) %7B%0A        
     
@@ -1174,117 +1174,21 @@
 .add
+All
 (tag
-.trim());%0A                %7D%0A            %7D else %7B%0A                posTags = new HashSet%3C%3E();%0A            %7D
+List);
 %0A   

modify parameter handling