diff options
author | Christoph Büscher <christoph@elastic.co> | 2016-01-28 20:04:15 +0100 |
---|---|---|
committer | Christoph Büscher <christoph@elastic.co> | 2016-02-08 12:28:12 +0100 |
commit | 2ae6420fd64f8b063b1a055ef37e85f7d0ba055a (patch) | |
tree | 3ca494a11409f4ee9d10787d1411bec6927d3bac /core/src/main/java/org/elasticsearch/search/suggest/completion | |
parent | 2dec12903842af471fe43b73b5acd7bbff8e9b61 (diff) |
Suggest: Add parsing from xContent to PhraseSuggestionBuilder
For the ongoing search refactoring (#10217) the PhraseSuggestionBuilder
gets a way of parsing from xContent that will eventually replace the
current SuggestParseElement. This PR adds the fromXContent method
to the PhraseSuggestionBuilder and also adds parsing code for the
common suggestion parameters to SuggestionBuilder.
Also adding links from the Suggester implementations registeres in the
Suggesters registry to the corresponding prototype that is going to
be used for parsing once the refactoring is done and we switch from
parsing on shard to parsing on coordinating node.
Diffstat (limited to 'core/src/main/java/org/elasticsearch/search/suggest/completion')
2 files changed, 16 insertions, 2 deletions
diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggester.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggester.java index 527a35658c..8cd9d386a1 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggester.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggester.java @@ -38,6 +38,7 @@ import org.elasticsearch.index.mapper.core.CompletionFieldMapper; import org.elasticsearch.search.suggest.Suggest; import org.elasticsearch.search.suggest.SuggestContextParser; import org.elasticsearch.search.suggest.Suggester; +import org.elasticsearch.search.suggest.SuggestionBuilder; import java.io.IOException; import java.util.ArrayList; @@ -50,6 +51,7 @@ import java.util.Set; public class CompletionSuggester extends Suggester<CompletionSuggestionContext> { + @Override public SuggestContextParser getContextParser() { return new CompletionSuggestParser(this); } @@ -86,7 +88,8 @@ public class CompletionSuggester extends Suggester<CompletionSuggestionContext> for (String field : payloadFields) { MappedFieldType payloadFieldType = suggestionContext.getMapperService().fullName(field); if (payloadFieldType != null) { - final AtomicFieldData data = suggestionContext.getIndexFieldDataService().getForField(payloadFieldType).load(subReaderContext); + final AtomicFieldData data = suggestionContext.getIndexFieldDataService().getForField(payloadFieldType) + .load(subReaderContext); final ScriptDocValues scriptValues = data.getScriptValues(); scriptValues.setNextDocId(subDocId); payload.put(field, new ArrayList<>(scriptValues.getValues())); @@ -262,4 +265,9 @@ public class CompletionSuggester extends Suggester<CompletionSuggestionContext> } } } + + @Override + public SuggestionBuilder<?> getBuilderPrototype() { + return CompletionSuggestionBuilder.PROTOTYPE; + } } 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 afa0760e70..29992c1a07 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 @@ -27,6 +27,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.unit.Fuzziness; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.query.RegexpFlag; import org.elasticsearch.search.suggest.SuggestionBuilder; import org.elasticsearch.search.suggest.completion.context.CategoryQueryContext; @@ -50,7 +51,7 @@ import java.util.Set; public class CompletionSuggestionBuilder extends SuggestionBuilder<CompletionSuggestionBuilder> { public static final CompletionSuggestionBuilder PROTOTYPE = new CompletionSuggestionBuilder("_na_"); // name doesn't matter - final static String SUGGESTION_NAME = "completion"; + static final String SUGGESTION_NAME = "completion"; static final ParseField PAYLOAD_FIELD = new ParseField("payload"); static final ParseField CONTEXTS_FIELD = new ParseField("contexts", "context"); @@ -370,6 +371,11 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder<CompletionSug } @Override + protected CompletionSuggestionBuilder innerFromXContent(QueryParseContext parseContext, String name) throws IOException { + return new CompletionSuggestionBuilder(name); + } + + @Override public String getWriteableName() { return SUGGESTION_NAME; } |