diff options
author | Christoph Büscher <christoph@elastic.co> | 2016-03-01 19:57:58 +0100 |
---|---|---|
committer | Christoph Büscher <christoph@elastic.co> | 2016-03-03 21:35:53 +0100 |
commit | 30a788d87cff159f2f2045a1b98216afcd10855b (patch) | |
tree | 0bbd95d5ad00eedf2b2dd8e8560020eea7785c7b /core/src/main/java/org/elasticsearch/search/suggest/completion | |
parent | ef4db5c1e45f98aca78d18e2ae8a3660eec41c35 (diff) |
Suggestions: Make field name mandatory ctor argument
The field name is a required argument for all suggesters, but
it was specified via a field() setter in SuggestionBuilder so far.
This changes field name to being a mandatory constructor argument
and lets suggestion builders throw an error if field name is missing
or the empty string.
Diffstat (limited to 'core/src/main/java/org/elasticsearch/search/suggest/completion')
-rw-r--r-- | core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestionBuilder.java | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestionBuilder.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestionBuilder.java index d8c7ededb9..f2540e4862 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestionBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestionBuilder.java @@ -50,7 +50,7 @@ import java.util.Set; */ public class CompletionSuggestionBuilder extends SuggestionBuilder<CompletionSuggestionBuilder> { - public static final CompletionSuggestionBuilder PROTOTYPE = new CompletionSuggestionBuilder(); + public static final CompletionSuggestionBuilder PROTOTYPE = new CompletionSuggestionBuilder("_na_"); static final String SUGGESTION_NAME = "completion"; static final ParseField PAYLOAD_FIELD = new ParseField("payload"); static final ParseField CONTEXTS_FIELD = new ParseField("contexts", "context"); @@ -60,6 +60,10 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder<CompletionSug private final Map<String, List<QueryContext>> queryContexts = new HashMap<>(); private final Set<String> payloadFields = new HashSet<>(); + public CompletionSuggestionBuilder(String fieldname) { + super(fieldname); + } + /** * Sets the prefix to provide completions for. * The prefix gets analyzed by the suggest analyzer. @@ -229,8 +233,8 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder<CompletionSug } @Override - public CompletionSuggestionBuilder doReadFrom(StreamInput in) throws IOException { - CompletionSuggestionBuilder completionSuggestionBuilder = new CompletionSuggestionBuilder(); + public CompletionSuggestionBuilder doReadFrom(StreamInput in, String fieldname) throws IOException { + CompletionSuggestionBuilder completionSuggestionBuilder = new CompletionSuggestionBuilder(fieldname); if (in.readBoolean()) { int numPayloadField = in.readVInt(); for (int i = 0; i < numPayloadField; i++) { |