Skip to content

Commit cf8035c

Browse files
committed
custom query params
1 parent c69e045 commit cf8035c

File tree

4 files changed

+71
-16
lines changed

4 files changed

+71
-16
lines changed

src/main/assembly/plugin.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
<exclude>**/dic/**</exclude>
2121
</excludes>
2222
</fileSet>
23+
24+
<fileSet>
25+
<directory>${project.basedir}/src/main/plugin-metadata</directory>
26+
<outputDirectory>/elasticsearch</outputDirectory>
27+
</fileSet>
2328
</fileSets>
2429
<files>
2530
<file>

src/main/java/org/ansj/elasticsearch/cat/AnsjCatAction.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.ansj.elasticsearch.action.AnsjAction;
44
import org.ansj.elasticsearch.action.AnsjRequest;
55
import org.ansj.elasticsearch.action.AnsjResponse;
6+
import org.ansj.library.*;
67
import org.elasticsearch.client.node.NodeClient;
78
import org.elasticsearch.common.Table;
89
import org.elasticsearch.common.inject.Inject;
@@ -13,6 +14,10 @@
1314
import org.elasticsearch.rest.action.RestResponseListener;
1415
import org.elasticsearch.rest.action.cat.AbstractCatAction;
1516

17+
import java.util.Arrays;
18+
import java.util.HashSet;
19+
import java.util.Set;
20+
1621
/**
1722
* Created by zhangqinghua on 16/2/2.
1823
*/
@@ -43,6 +48,15 @@ public RestResponse buildResponse(final AnsjResponse ansjResponse) throws Except
4348
});
4449
}
4550

51+
@Override
52+
protected Set<String> responseParams() {
53+
Set<String> responseParams = new HashSet<>(super.responseParams());
54+
responseParams.addAll(Arrays.asList("text", "analyzer", "tokenizer", "type", "key",
55+
"isNameRecognition", "isNumRecognition", "isQuantifierRecognition", "isRealName", "isSkipUserDefine",
56+
CrfLibrary.DEFAULT, DicLibrary.DEFAULT, AmbiguityLibrary.DEFAULT, StopLibrary.DEFAULT, SynonymsLibrary.DEFAULT));
57+
return responseParams;
58+
}
59+
4660
@Override
4761
protected void documentation(StringBuilder stringBuilder) {
4862

src/main/java/org/ansj/elasticsearch/index/config/AnsjElasticConfigurator.java

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.ansj.splitWord.analysis.ToAnalysis;
1010
import org.ansj.util.MyStaticValue;
1111
import org.apache.logging.log4j.Logger;
12+
import org.elasticsearch.SpecialPermission;
1213
import org.elasticsearch.common.inject.Inject;
1314
import org.elasticsearch.common.logging.Loggers;
1415
import org.elasticsearch.common.settings.Settings;
@@ -22,6 +23,8 @@
2223
import java.nio.file.Files;
2324
import java.nio.file.Path;
2425
import java.nio.file.Paths;
26+
import java.security.AccessController;
27+
import java.security.PrivilegedAction;
2528
import java.util.Map;
2629

2730
public class AnsjElasticConfigurator {
@@ -90,25 +93,34 @@ private void flushConfig() {
9093
}
9194

9295
private void initConfig(String path, boolean printErr) {
93-
try (BufferedReader br = IOUtil.getReader(PathToStream.stream(path), "utf-8")) {
94-
String temp;
95-
int index;
96-
while ((temp = br.readLine()) != null) {
97-
if (StringUtil.isBlank(temp) || temp.trim().charAt(0) == '#' || !temp.contains("=")) {
98-
continue;
99-
}
96+
final SecurityManager sm = System.getSecurityManager();
97+
if (sm != null) {
98+
sm.checkPermission(new SpecialPermission());
99+
}
100+
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
101+
try (BufferedReader br = IOUtil.getReader(PathToStream.stream(path), "utf-8")) {
102+
String temp, key;
103+
int index;
104+
while ((temp = br.readLine()) != null) {
105+
if (StringUtil.isBlank(temp) || temp.trim().charAt(0) == '#' || !temp.contains("=")) {
106+
continue;
107+
}
100108

101-
index = temp.indexOf('=');
109+
index = temp.indexOf('=');
102110

103-
MyStaticValue.ENV.put(temp.substring(0, index).trim(), temp.substring(index + 1, temp.length()).trim());
104-
}
105-
} catch (Exception e) {
106-
if (printErr) {
107-
LOG.error("{} load err: {}", path, e);
108-
} else {
109-
LOG.warn("{} load err", path);
111+
MyStaticValue.ENV.put(key = temp.substring(0, index).trim(), temp.substring(index + 1, temp.length()).trim());
112+
113+
DicLibrary.get(key);
114+
}
115+
} catch (Exception e) {
116+
if (printErr) {
117+
LOG.error("{} load err: {}", path, e);
118+
} else {
119+
LOG.warn("{} load err", path);
120+
}
110121
}
111-
}
122+
return null;
123+
});
112124
}
113125

114126
private void preheat() {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
grant {
21+
permission java.lang.RuntimePermission "getClassLoader";
22+
permission java.lang.RuntimePermission "setContextClassLoader";
23+
permission java.io.FilePermission "<<ALL FILES>>", "read,write";
24+
};

0 commit comments

Comments
 (0)