Skip to content

Commit

Permalink
es 8.7.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
shi-yuan committed Apr 3, 2023
1 parent 979f8ce commit 7ead9e2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 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>8.6.2.0</version>
<version>8.7.0.0</version>
<description>elasticsearch analysis by ansj</description>
<name>elasticsearch-analysis-ansj</name>
<url>http://maven.nlpcn.org</url>
Expand All @@ -14,7 +14,7 @@
<runSuite>**/MainTestSuite.class</runSuite>
<elasticsearch.plugin.name>elasticsearch-analysis-ansj</elasticsearch.plugin.name>
<elasticsearch.plugin.java.version>17</elasticsearch.plugin.java.version>
<elasticsearch.version>8.6.2</elasticsearch.version>
<elasticsearch.version>8.7.0</elasticsearch.version>
<elasticsearch.plugin.classname>org.ansj.elasticsearch.plugin.AnalysisAnsjPlugin</elasticsearch.plugin.classname>
</properties>

Expand Down
17 changes: 10 additions & 7 deletions src/main/java/org/ansj/elasticsearch/cat/ChineseRestTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import org.elasticsearch.common.Strings;
import org.elasticsearch.common.Table;
import org.elasticsearch.common.io.UTF8StreamWriter;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.io.stream.BytesStream;
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.unit.ByteSizeValue;
Expand All @@ -36,6 +36,8 @@
import org.elasticsearch.xcontent.XContentType;

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
Expand All @@ -57,11 +59,11 @@ public static RestResponse buildResponse(Table table, RestChannel channel) throw
}

public static RestResponse response(RestChannel channel, String text) throws IOException {
try (UTF8StreamWriter out = new UTF8StreamWriter(); BytesStream bytesOut = channel.bytesOutput()) {
out.setOutput(bytesOut);
BytesStream bytesOut = Streams.flushOnCloseStream(channel.bytesOutput());
try (OutputStreamWriter out = new OutputStreamWriter(bytesOut, StandardCharsets.UTF_8)) {
out.append(text);
return new RestResponse(RestStatus.OK, RestResponse.TEXT_CONTENT_TYPE, bytesOut.bytes());
}
return new RestResponse(RestStatus.OK, RestResponse.TEXT_CONTENT_TYPE, bytesOut.bytes());
}

public static RestResponse response(RestChannel channel, Map<String, Object> map) throws IOException {
Expand Down Expand Up @@ -96,7 +98,8 @@ public static RestResponse buildTextPlainResponse(Table table, RestChannel chann
List<DisplayHeader> headers = buildDisplayHeaders(table, request);
int[] width = buildWidths(table, request, verbose, headers);

try (BytesStream bytesOut = channel.bytesOutput(); UTF8StreamWriter out = new UTF8StreamWriter().setOutput(bytesOut)) {
BytesStream bytesOut = Streams.flushOnCloseStream(channel.bytesOutput());
try (OutputStreamWriter out = new OutputStreamWriter(bytesOut, StandardCharsets.UTF_8)) {
if (verbose) {
for (int col = 0; col < headers.size(); col++) {
DisplayHeader header = headers.get(col);
Expand All @@ -113,8 +116,8 @@ public static RestResponse buildTextPlainResponse(Table table, RestChannel chann
}
out.append("\n");
}
return new RestResponse(RestStatus.OK, RestResponse.TEXT_CONTENT_TYPE, bytesOut.bytes());
}
return new RestResponse(RestStatus.OK, RestResponse.TEXT_CONTENT_TYPE, bytesOut.bytes());
}

private static List<DisplayHeader> buildDisplayHeaders(Table table, RestRequest request) {
Expand Down Expand Up @@ -258,7 +261,7 @@ private static int[] buildWidths(Table table, RestRequest request, boolean verbo
return width;
}

public static void pad(Table.Cell cell, int width, RestRequest request, UTF8StreamWriter out) throws IOException {
public static void pad(Table.Cell cell, int width, RestRequest request, OutputStreamWriter out) throws IOException {
String sValue = renderValue(request, cell.value);
int length = sValue == null ? 0 : sValue.length();
byte leftOver = (byte) (width - length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.settings.ClusterSettings;
Expand Down Expand Up @@ -54,7 +54,7 @@ public class AnalysisAnsjPlugin extends Plugin implements AnalysisPlugin, Action
private static final Logger LOG = LogManager.getLogger();

@Override
public Collection<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool, ResourceWatcherService resourceWatcherService, ScriptService scriptService, NamedXContentRegistry xContentRegistry, Environment environment, NodeEnvironment nodeEnvironment, NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier<RepositoriesService> repositoriesServiceSupplier, Tracer tracer, AllocationDeciders allocationDeciders) {
public Collection<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool, ResourceWatcherService resourceWatcherService, ScriptService scriptService, NamedXContentRegistry xContentRegistry, Environment environment, NodeEnvironment nodeEnvironment, NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier<RepositoriesService> repositoriesServiceSupplier, Tracer tracer, AllocationService allocationService) {
return Collections.singletonList(new AnsjElasticConfigurator(environment));
}

Expand Down

0 comments on commit 7ead9e2

Please sign in to comment.