Skip to content

Commit

Permalink
es 6.4.2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
shi-yuan committed Oct 13, 2018
1 parent 66d1856 commit 5c08516
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 25 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.ansj</groupId>
<artifactId>elasticsearch-analysis-ansj</artifactId>
<version>6.4.1.0</version>
<version>6.4.2.0</version>
<description>elasticsearch analysis by ansj</description>
<name>elasticsearch-analysis-ansj</name>
<url>http://maven.nlpcn.org</url>
Expand All @@ -21,7 +21,7 @@
<runSuite>**/MainTestSuite.class</runSuite>
<elasticsearch.plugin.name>elasticsearch-analysis-ansj</elasticsearch.plugin.name>
<elasticsearch.plugin.java.version>1.8</elasticsearch.plugin.java.version>
<elasticsearch.version>6.4.1</elasticsearch.version>
<elasticsearch.version>6.4.2</elasticsearch.version>
<elasticsearch.plugin.classname>org.ansj.elasticsearch.plugin.AnalysisAnsjPlugin</elasticsearch.plugin.classname>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public AnsjAnalyzerProvider(IndexSettings indexSettings, @Assisted String name,

Map<String, String> 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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Tokenizer create() {

Map<String, String> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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() {
Expand All @@ -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<Void>) () -> {
try (BufferedReader br = IOUtil.getReader(PathToStream.stream(path), "utf-8")) {
String temp;
Expand All @@ -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<Void>) () -> {
Expand Down Expand Up @@ -195,7 +195,8 @@ private void setGlobalVar(Map<String, String> 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));
Expand Down Expand Up @@ -230,6 +231,6 @@ public static Map<String, String> getDefaults() {
.put(StopLibrary.DEFAULT, StopLibrary.DEFAULT)
.put(SynonymsLibrary.DEFAULT, SynonymsLibrary.DEFAULT)
.put(AmbiguityLibrary.DEFAULT, AmbiguityLibrary.DEFAULT)
.map();
.immutableMap();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Module> createGuiceModules() {
return Collections.singletonList(new AnsjModule());
Expand Down

0 comments on commit 5c08516

Please sign in to comment.