summaryrefslogtreecommitdiff
path: root/core/src/main/java/org/elasticsearch/search/suggest/completion
diff options
context:
space:
mode:
authorChristoph Büscher <christoph@elastic.co>2016-02-22 11:46:47 -0800
committerChristoph Büscher <christoph@elastic.co>2016-03-01 17:34:47 +0100
commitbe8ed737bc3af18d2ae4c9ad332e32900911a85a (patch)
treef1dcd8d0156c0be11b6fe3feb898c25c40ca9900 /core/src/main/java/org/elasticsearch/search/suggest/completion
parentaecf51cb42ea1abf1399989a23cae296542bfe6c (diff)
Suggest: Move name of suggestion to SuggestBuilder
Currently each suggestion keeps track of its own name. This has the disadvantage of having to pass down the parsed name property in the suggestions fromXContent() and the serialization methods as an argument, since we need it in the ctor. This change moves the naming of the suggestions to the surrounding SuggestBuilder and by this eliminates the need for passind down the names in the parsing and serialization methods. By making `name` a required argument in SuggestBuilder#addSuggestion() we also make sure it is always set and prevent using the same name twice, which wasn't possible before.
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.java12
1 files changed, 4 insertions, 8 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 3c7bf08502..d8c7ededb9 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("_na_"); // name doesn't matter
+ public static final CompletionSuggestionBuilder PROTOTYPE = new CompletionSuggestionBuilder();
static final String SUGGESTION_NAME = "completion";
static final ParseField PAYLOAD_FIELD = new ParseField("payload");
static final ParseField CONTEXTS_FIELD = new ParseField("contexts", "context");
@@ -60,10 +60,6 @@ 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 name) {
- super(name);
- }
-
/**
* Sets the prefix to provide completions for.
* The prefix gets analyzed by the suggest analyzer.
@@ -179,7 +175,7 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder<CompletionSug
}
@Override
- protected CompletionSuggestionBuilder innerFromXContent(QueryParseContext parseContext, String name) throws IOException {
+ protected CompletionSuggestionBuilder innerFromXContent(QueryParseContext parseContext) throws IOException {
// NORELEASE implement parsing logic
throw new UnsupportedOperationException();
}
@@ -233,8 +229,8 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder<CompletionSug
}
@Override
- public CompletionSuggestionBuilder doReadFrom(StreamInput in, String name) throws IOException {
- CompletionSuggestionBuilder completionSuggestionBuilder = new CompletionSuggestionBuilder(name);
+ public CompletionSuggestionBuilder doReadFrom(StreamInput in) throws IOException {
+ CompletionSuggestionBuilder completionSuggestionBuilder = new CompletionSuggestionBuilder();
if (in.readBoolean()) {
int numPayloadField = in.readVInt();
for (int i = 0; i < numPayloadField; i++) {