From beceb4bf8ac31d513ab3c352d261c22351ff85cb Mon Sep 17 00:00:00 2001 From: Matt Weber Date: Fri, 13 Jan 2017 06:12:49 -0800 Subject: [PATCH] Analyze API Position Length Support (#22574) Expose the position length attribute if a token has a non-standard position length greater than 1. --- .../analyze/AnalyzeRequestBuilder.java | 2 +- .../indices/analyze/AnalyzeResponse.java | 25 +++++- .../analyze/TransportAnalyzeAction.java | 8 +- .../indices/analyze/AnalyzeActionIT.java | 79 ++++++++++++++++++- 4 files changed, 105 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequestBuilder.java index 344681b997e..5070862ed69 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequestBuilder.java @@ -113,7 +113,7 @@ public class AnalyzeRequestBuilder extends SingleShardOperationRequestBuilder attributes; private String type; AnalyzeToken() { } - public AnalyzeToken(String term, int position, int startOffset, int endOffset, String type, - Map attributes) { + public AnalyzeToken(String term, int position, int startOffset, int endOffset, int positionLength, + String type, Map attributes) { this.term = term; this.position = position; this.startOffset = startOffset; this.endOffset = endOffset; + this.positionLength = positionLength; this.type = type; this.attributes = attributes; } @@ -71,6 +73,10 @@ public class AnalyzeResponse extends ActionResponse implements Iterable 1) { + builder.field(Fields.POSITION_LENGTH, positionLength); + } if (attributes != null && !attributes.isEmpty()) { for (Map.Entry entity : attributes.entrySet()) { builder.field(entity.getKey(), entity.getValue()); @@ -108,6 +117,14 @@ public class AnalyzeResponse extends ActionResponse implements Iterable) in.readGenericValue(); @@ -120,6 +137,9 @@ public class AnalyzeResponse extends ActionResponse implements Iterable 1 ? positionLength : null); + } out.writeOptionalString(type); if (out.getVersion().onOrAfter(Version.V_2_2_0)) { out.writeGenericValue(attributes); @@ -208,6 +228,7 @@ public class AnalyzeResponse extends ActionResponse implements Iterable 0) { lastPosition = lastPosition + increment; } - tokens.add(new AnalyzeResponse.AnalyzeToken(term.toString(), lastPosition, lastOffset + offset.startOffset(), lastOffset + offset.endOffset(), type.type(), null)); + tokens.add(new AnalyzeResponse.AnalyzeToken(term.toString(), lastPosition, lastOffset + offset.startOffset(), + lastOffset + offset.endOffset(), posLen.getPositionLength(), type.type(), null)); } stream.end(); @@ -381,6 +384,7 @@ public class TransportAnalyzeAction extends TransportSingleShardAction