From da24bfe5421972c14874f8420689a480642228d2 Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Wed, 16 Mar 2016 19:40:25 -0400 Subject: [PATCH] simplify handling top-level suggest results --- .../action/suggest/RestSuggestAction.java | 2 +- .../controller/SearchPhaseController.java | 2 +- .../internal/InternalSearchResponse.java | 2 +- .../search/query/QuerySearchResult.java | 2 +- .../elasticsearch/search/suggest/Suggest.java | 45 +++++++------------ .../search/suggest/SuggestPhase.java | 2 +- 6 files changed, 21 insertions(+), 34 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/rest/action/suggest/RestSuggestAction.java b/core/src/main/java/org/elasticsearch/rest/action/suggest/RestSuggestAction.java index 291eb69254b..53d9e668de1 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/suggest/RestSuggestAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/suggest/RestSuggestAction.java @@ -97,7 +97,7 @@ public class RestSuggestAction extends BaseRestHandler { buildBroadcastShardsHeader(builder, request, response); Suggest suggest = response.getSuggest(); if (suggest != null) { - suggest.toXContent(builder, request); + suggest.toInnerXContent(builder, request); } builder.endObject(); return new BytesRestResponse(restStatus, builder); diff --git a/core/src/main/java/org/elasticsearch/search/controller/SearchPhaseController.java b/core/src/main/java/org/elasticsearch/search/controller/SearchPhaseController.java index 68343ba5959..d5d4607fba9 100644 --- a/core/src/main/java/org/elasticsearch/search/controller/SearchPhaseController.java +++ b/core/src/main/java/org/elasticsearch/search/controller/SearchPhaseController.java @@ -386,7 +386,7 @@ public class SearchPhaseController extends AbstractComponent { Suggest.group(groupedSuggestions, shardResult); } - suggest = hasSuggestions ? new Suggest(Suggest.Fields.SUGGEST, Suggest.reduce(groupedSuggestions)) : null; + suggest = hasSuggestions ? new Suggest(Suggest.reduce(groupedSuggestions)) : null; } // merge addAggregation diff --git a/core/src/main/java/org/elasticsearch/search/internal/InternalSearchResponse.java b/core/src/main/java/org/elasticsearch/search/internal/InternalSearchResponse.java index b8255e0bb52..1a2e1f70191 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/InternalSearchResponse.java +++ b/core/src/main/java/org/elasticsearch/search/internal/InternalSearchResponse.java @@ -134,7 +134,7 @@ public class InternalSearchResponse implements Streamable, ToXContent { aggregations = InternalAggregations.readAggregations(in); } if (in.readBoolean()) { - suggest = Suggest.readSuggest(Suggest.Fields.SUGGEST, in); + suggest = Suggest.readSuggest(in); } timedOut = in.readBoolean(); diff --git a/core/src/main/java/org/elasticsearch/search/query/QuerySearchResult.java b/core/src/main/java/org/elasticsearch/search/query/QuerySearchResult.java index 9223eb5a82d..2b82633ebfd 100644 --- a/core/src/main/java/org/elasticsearch/search/query/QuerySearchResult.java +++ b/core/src/main/java/org/elasticsearch/search/query/QuerySearchResult.java @@ -207,7 +207,7 @@ public class QuerySearchResult extends QuerySearchResultProvider { this.pipelineAggregators = pipelineAggregators; } if (in.readBoolean()) { - suggest = Suggest.readSuggest(Suggest.Fields.SUGGEST, in); + suggest = Suggest.readSuggest(in); } searchTimedOut = in.readBoolean(); terminatedEarly = in.readOptionalBoolean(); diff --git a/core/src/main/java/org/elasticsearch/search/suggest/Suggest.java b/core/src/main/java/org/elasticsearch/search/suggest/Suggest.java index f2a217b14c8..f9c7092fbf1 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/Suggest.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/Suggest.java @@ -46,9 +46,7 @@ import java.util.Map; */ public class Suggest implements Iterable>>, Streamable, ToXContent { - public static class Fields { - public static final XContentBuilderString SUGGEST = new XContentBuilderString("suggest"); - } + private static final XContentBuilderString NAME = new XContentBuilderString("suggest"); private static final Comparator