diff --git a/pom.xml b/pom.xml
index 99e0721..a651b4c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
org.ansj
elasticsearch-analysis-ansj
- 6.4.1.0
+ 6.4.2.0
elasticsearch analysis by ansj
elasticsearch-analysis-ansj
http://maven.nlpcn.org
@@ -21,7 +21,7 @@
**/MainTestSuite.class
elasticsearch-analysis-ansj
1.8
- 6.4.1
+ 6.4.2
org.ansj.elasticsearch.plugin.AnalysisAnsjPlugin
diff --git a/src/main/java/org/ansj/elasticsearch/action/TransportAnsjAction.java b/src/main/java/org/ansj/elasticsearch/action/TransportAnsjAction.java
index 78a99de..b93a135 100644
--- a/src/main/java/org/ansj/elasticsearch/action/TransportAnsjAction.java
+++ b/src/main/java/org/ansj/elasticsearch/action/TransportAnsjAction.java
@@ -358,10 +358,7 @@ private AnsjResponse flushDic(AnsjRequest request) {
String key = (String) params.get("key");
- final SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- sm.checkPermission(new SpecialPermission());
- }
+ SpecialPermission.check();
try {
if (key.startsWith(DicLibrary.DEFAULT)) {
diff --git a/src/main/java/org/ansj/elasticsearch/index/analysis/AnsjAnalyzerProvider.java b/src/main/java/org/ansj/elasticsearch/index/analysis/AnsjAnalyzerProvider.java
index 929f51f..54dd8e5 100644
--- a/src/main/java/org/ansj/elasticsearch/index/analysis/AnsjAnalyzerProvider.java
+++ b/src/main/java/org/ansj/elasticsearch/index/analysis/AnsjAnalyzerProvider.java
@@ -27,7 +27,7 @@ public AnsjAnalyzerProvider(IndexSettings indexSettings, @Assisted String name,
Map args = settings2.keySet().stream().collect(Collectors.toMap(k -> k, settings2::get));
if (args.isEmpty()) {
- args = AnsjElasticConfigurator.getDefaults();
+ args.putAll(AnsjElasticConfigurator.getDefaults());
args.put("type", name());
}
diff --git a/src/main/java/org/ansj/elasticsearch/index/analysis/AnsjTokenizerTokenizerFactory.java b/src/main/java/org/ansj/elasticsearch/index/analysis/AnsjTokenizerTokenizerFactory.java
index c7f50c0..0578ad4 100644
--- a/src/main/java/org/ansj/elasticsearch/index/analysis/AnsjTokenizerTokenizerFactory.java
+++ b/src/main/java/org/ansj/elasticsearch/index/analysis/AnsjTokenizerTokenizerFactory.java
@@ -51,7 +51,7 @@ public Tokenizer create() {
Map args = settings.keySet().stream().collect(Collectors.toMap(k -> k, settings::get));
if (args.isEmpty()) {
- args = AnsjElasticConfigurator.getDefaults();
+ args.putAll(AnsjElasticConfigurator.getDefaults());
args.put("type", this.name);
}
diff --git a/src/main/java/org/ansj/elasticsearch/index/config/AnsjElasticConfigurator.java b/src/main/java/org/ansj/elasticsearch/index/config/AnsjElasticConfigurator.java
index c49d1ae..2041c71 100644
--- a/src/main/java/org/ansj/elasticsearch/index/config/AnsjElasticConfigurator.java
+++ b/src/main/java/org/ansj/elasticsearch/index/config/AnsjElasticConfigurator.java
@@ -37,8 +37,19 @@ public class AnsjElasticConfigurator {
private File configDir;
+ private Environment env;
+
@Inject
public AnsjElasticConfigurator(Environment env) {
+ this.env = env;
+
+ //
+ init();
+
+ LOG.info("init ansj plugin ok , goodluck youyou");
+ }
+
+ private void init() {
Path configFilePath = env.configFile().resolve("elasticsearch-analysis-ansj").resolve(CONFIG_FILE_NAME);
LOG.info("try to load ansj config file: {}", configFilePath);
if (!Files.exists(configFilePath)) {
@@ -58,18 +69,14 @@ public AnsjElasticConfigurator(Environment env) {
}
Settings settings = builder.build();
-
path = settings.get("ansj_config");
-
ansjSettings = settings.getAsSettings("ansj");
-
configDir = env.configFile().toFile();
flushConfig();
// 进行一次测试分词
preheat();
- LOG.info("init ansj plugin ok , goodluck youyou");
}
private void flushConfig() {
@@ -94,10 +101,7 @@ private void flushConfig() {
}
private void initConfig(String path, boolean printErr) {
- final SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- sm.checkPermission(new SpecialPermission());
- }
+ SpecialPermission.check();
AccessController.doPrivileged((PrivilegedAction) () -> {
try (BufferedReader br = IOUtil.getReader(PathToStream.stream(path), "utf-8")) {
String temp;
@@ -123,11 +127,7 @@ private void initConfig(String path, boolean printErr) {
}
private void initDic() {
- final SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- sm.checkPermission(new SpecialPermission());
- }
-
+ SpecialPermission.check();
MyStaticValue.ENV.forEach((k, v) -> {
if (k.startsWith(DicLibrary.DEFAULT)) {
AccessController.doPrivileged((PrivilegedAction) () -> {
@@ -195,7 +195,8 @@ private void setGlobalVar(Map map) {
}
public void reloadConfig() {
- flushConfig();
+ init();
+ LOG.info("reload ansj plugin config successfully");
LOG.info("to remove DicLibrary keys not in MyStaticValue.ENV");
DicLibrary.keys().removeIf(key -> !MyStaticValue.ENV.containsKey(key));
@@ -230,6 +231,6 @@ public static Map getDefaults() {
.put(StopLibrary.DEFAULT, StopLibrary.DEFAULT)
.put(SynonymsLibrary.DEFAULT, SynonymsLibrary.DEFAULT)
.put(AmbiguityLibrary.DEFAULT, AmbiguityLibrary.DEFAULT)
- .map();
+ .immutableMap();
}
}
diff --git a/src/main/java/org/ansj/elasticsearch/plugin/AnalysisAnsjPlugin.java b/src/main/java/org/ansj/elasticsearch/plugin/AnalysisAnsjPlugin.java
index a869fb4..bed99be 100644
--- a/src/main/java/org/ansj/elasticsearch/plugin/AnalysisAnsjPlugin.java
+++ b/src/main/java/org/ansj/elasticsearch/plugin/AnalysisAnsjPlugin.java
@@ -38,8 +38,6 @@ public class AnalysisAnsjPlugin extends Plugin implements AnalysisPlugin, Action
private static final Logger LOG = Loggers.getLogger(AnalysisAnsjPlugin.class);
- public static final String PLUGIN_NAME = "analysis-ansj";
-
@Override
public Collection createGuiceModules() {
return Collections.singletonList(new AnsjModule());