/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ginobefunny.elasticsearch.plugins.synonym;

import com.ginobefunny.elasticsearch.plugins.synonym.service.Configuration;
import com.ginobefunny.elasticsearch.plugins.synonym.service.DynamicSynonymTokenFilter;
import com.ginobefunny.elasticsearch.plugins.synonym.service.SynonymRuleManager;
import com.ginobefunny.elasticsearch.plugins.synonym.service.utils.Monitor;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.core.KeywordAnalyzer;
import org.apache.lucene.analysis.core.SimpleAnalyzer;
import org.apache.lucene.analysis.core.WhitespaceAnalyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.analysis.AbstractTokenFilterFactory;

import java.io.IOException;

public class DynamicSynonymTokenFilterFactory extends AbstractTokenFilterFactory {

    private static final Logger LOGGER = ESLoggerFactory.getLogger(Monitor.class.getName());

    public DynamicSynonymTokenFilterFactory(IndexSettings indexSettings, Environment env,
                                            String name, Settings settings) throws IOException {
        super(indexSettings, name, settings);

        // get the filter setting params
        final boolean ignoreCase = settings.getAsBoolean("ignore_case", false);
        final boolean expand = settings.getAsBoolean("expand", true);
        final String dbUrl = settings.get("db_url");
        final String tokenizerName = settings.get("tokenizer", "whitespace");

        LOGGER.info("[DynamicSynonymTokenFilterFactory.new][name={}][ignoreCase={}][expand={}][dbUrl={}][tokenizerName={}]", name, ignoreCase, expand, dbUrl, tokenizerName);

        Analyzer analyzer;
        if ("standand".equalsIgnoreCase(tokenizerName)) {
            analyzer = new StandardAnalyzer();
        } else if ("keyword".equalsIgnoreCase(tokenizerName)) {
            analyzer = new KeywordAnalyzer();
        } else if ("simple".equalsIgnoreCase(tokenizerName)) {
            analyzer = new SimpleAnalyzer();
        } else {
            analyzer = new WhitespaceAnalyzer();
        }

        // NOTE: the manager will only init once
        SynonymRuleManager.initial(new Configuration(ignoreCase, expand, analyzer, dbUrl));
    }

    @Override
    public TokenStream create(TokenStream tokenStream) {
        LOGGER.info("[DynamicSynonymTokenFilterFactory.create]");
        return new DynamicSynonymTokenFilter(tokenStream);
    }
}

@@ -856,124 +856,8 @@
 er;%0A
-import com.ginobefunny.elasticsearch.plugins.synonym.service.utils.Monitor;%0Aimport org.apache.logging.log4j.Logger;%0A
 impo
@@ -888,32 +888,32 @@
 lysis.Analyzer;%0A
+
 import org.apach
@@ -1178,65 +1178,8 @@
 er;%0A
-import org.elasticsearch.common.logging.ESLoggerFactory;%0A
 impo
@@ -1499,102 +1499,8 @@
  %7B%0A%0A
-    private static final Logger LOGGER = ESLoggerFactory.getLogger(Monitor.class.getName());%0A%0A
     
@@ -2056,183 +2056,8 @@
 );%0A%0A
-        LOGGER.info(%22%5BDynamicSynonymTokenFilterFactory.new%5D%5Bname=%7B%7D%5D%5BignoreCase=%7B%7D%5D%5Bexpand=%7B%7D%5D%5BdbUrl=%7B%7D%5D%5BtokenizerName=%7B%7D%5D%22, name, ignoreCase, expand, dbUrl, tokenizerName);%0A%0A
     
@@ -2641,16 +2641,16 @@
 verride%0A
+
     publ
@@ -2702,74 +2702,8 @@
 ) %7B%0A
-        LOGGER.info(%22%5BDynamicSynonymTokenFilterFactory.create%5D%22);%0A
     

remove test log