diff options
Diffstat (limited to 'core/src/main/java/org/elasticsearch/search/suggest/completion')
4 files changed, 30 insertions, 49 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 049883822d..625458f2c9 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 @@ -29,18 +29,14 @@ import org.apache.lucene.search.suggest.document.TopSuggestDocs; import org.apache.lucene.search.suggest.document.TopSuggestDocsCollector; import org.apache.lucene.util.CharsRefBuilder; import org.apache.lucene.util.PriorityQueue; -import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.text.Text; import org.elasticsearch.index.mapper.CompletionFieldMapper; -import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.search.suggest.Suggest; import org.elasticsearch.search.suggest.Suggester; -import org.elasticsearch.search.suggest.SuggestionBuilder; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; -import java.util.Comparator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -241,14 +237,4 @@ public class CompletionSuggester extends Suggester<CompletionSuggestionContext> } } } - - @Override - public SuggestionBuilder<?> innerFromXContent(QueryParseContext context) throws IOException { - return CompletionSuggestionBuilder.innerFromXContent(context); - } - - @Override - public SuggestionBuilder<?> read(StreamInput in) throws IOException { - return new CompletionSuggestionBuilder(in); - } } 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 0fd3726384..7ef1a000e4 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 @@ -20,7 +20,6 @@ package org.elasticsearch.search.suggest.completion; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -34,7 +33,6 @@ import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.mapper.CompletionFieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MapperService; -import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.search.suggest.SuggestionBuilder; import org.elasticsearch.search.suggest.SuggestionSearchContext.SuggestionContext; @@ -67,27 +65,26 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder<CompletionSug * "payload" : STRING_ARRAY * } */ - private static ObjectParser<CompletionSuggestionBuilder.InnerBuilder, ParseFieldMatcherSupplier> TLP_PARSER = - new ObjectParser<>(SUGGESTION_NAME, null); + private static final ObjectParser<CompletionSuggestionBuilder.InnerBuilder, Void> PARSER = new ObjectParser<>(SUGGESTION_NAME, null); static { - TLP_PARSER.declareField((parser, completionSuggestionContext, context) -> { + PARSER.declareField((parser, completionSuggestionContext, context) -> { if (parser.currentToken() == XContentParser.Token.VALUE_BOOLEAN) { if (parser.booleanValue()) { completionSuggestionContext.fuzzyOptions = new FuzzyOptions.Builder().build(); } } else { - completionSuggestionContext.fuzzyOptions = FuzzyOptions.parse(parser, context); + completionSuggestionContext.fuzzyOptions = FuzzyOptions.parse(parser); } }, FuzzyOptions.FUZZY_OPTIONS, ObjectParser.ValueType.OBJECT_OR_BOOLEAN); - TLP_PARSER.declareField((parser, completionSuggestionContext, context) -> - completionSuggestionContext.regexOptions = RegexOptions.parse(parser, context), + PARSER.declareField((parser, completionSuggestionContext, context) -> + completionSuggestionContext.regexOptions = RegexOptions.parse(parser), RegexOptions.REGEX_OPTIONS, ObjectParser.ValueType.OBJECT); - TLP_PARSER.declareString(CompletionSuggestionBuilder.InnerBuilder::field, FIELDNAME_FIELD); - TLP_PARSER.declareString(CompletionSuggestionBuilder.InnerBuilder::analyzer, ANALYZER_FIELD); - TLP_PARSER.declareInt(CompletionSuggestionBuilder.InnerBuilder::size, SIZE_FIELD); - TLP_PARSER.declareInt(CompletionSuggestionBuilder.InnerBuilder::shardSize, SHARDSIZE_FIELD); - TLP_PARSER.declareField((p, v, c) -> { + PARSER.declareString(CompletionSuggestionBuilder.InnerBuilder::field, FIELDNAME_FIELD); + PARSER.declareString(CompletionSuggestionBuilder.InnerBuilder::analyzer, ANALYZER_FIELD); + PARSER.declareInt(CompletionSuggestionBuilder.InnerBuilder::size, SIZE_FIELD); + PARSER.declareInt(CompletionSuggestionBuilder.InnerBuilder::shardSize, SHARDSIZE_FIELD); + PARSER.declareField((p, v, c) -> { // Copy the current structure. We will parse, once the mapping is provided XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.copyCurrentStructure(p); @@ -237,9 +234,9 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder<CompletionSug return builder; } - static CompletionSuggestionBuilder innerFromXContent(QueryParseContext parseContext) throws IOException { + public static CompletionSuggestionBuilder fromXContent(XContentParser parser) throws IOException { CompletionSuggestionBuilder.InnerBuilder builder = new CompletionSuggestionBuilder.InnerBuilder(); - TLP_PARSER.parse(parseContext.parser(), builder, parseContext); + PARSER.parse(parser, builder, null); String field = builder.field; // now we should have field name, check and copy fields over to the suggestion builder we return if (field == null) { diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/FuzzyOptions.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/FuzzyOptions.java index 3ae05f9ecf..8d121b24f1 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/completion/FuzzyOptions.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/FuzzyOptions.java @@ -22,7 +22,6 @@ package org.elasticsearch.search.suggest.completion; import org.apache.lucene.search.suggest.document.FuzzyCompletionQuery; import org.apache.lucene.util.automaton.Operations; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; @@ -56,7 +55,7 @@ public class FuzzyOptions implements ToXContent, Writeable { * "max_determinized_states" : INT * } */ - private static ObjectParser<Builder, ParseFieldMatcherSupplier> PARSER = new ObjectParser<>(FUZZY_OPTIONS.getPreferredName(), + private static final ObjectParser<Builder, Void> PARSER = new ObjectParser<>(FUZZY_OPTIONS.getPreferredName(), Builder::new); static { PARSER.declareInt(Builder::setFuzzyMinLength, MIN_LENGTH_FIELD); @@ -67,6 +66,14 @@ public class FuzzyOptions implements ToXContent, Writeable { PARSER.declareField(Builder::setFuzziness, Fuzziness::parse, Fuzziness.FIELD, ObjectParser.ValueType.VALUE); } + static FuzzyOptions parse(XContentParser parser) throws IOException { + return PARSER.parse(parser, null).build(); + } + + public static Builder builder() { + return new Builder(); + } + private int editDistance; private boolean transpositions; private int fuzzyMinLength; @@ -106,14 +113,6 @@ public class FuzzyOptions implements ToXContent, Writeable { out.writeVInt(maxDeterminizedStates); } - static FuzzyOptions parse(XContentParser parser, ParseFieldMatcherSupplier context) throws IOException { - return PARSER.parse(parser, context).build(); - } - - public static Builder builder() { - return new Builder(); - } - /** * Returns the maximum number of edits */ diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/RegexOptions.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/RegexOptions.java index a9209044c8..f330322a9f 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/completion/RegexOptions.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/RegexOptions.java @@ -23,7 +23,6 @@ import org.apache.lucene.util.automaton.Operations; import org.apache.lucene.util.automaton.RegExp; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; @@ -49,7 +48,7 @@ public class RegexOptions implements ToXContent, Writeable { * "max_determinized_states" : INT * } */ - private static ObjectParser<Builder, ParseFieldMatcherSupplier> PARSER = new ObjectParser<>(REGEX_OPTIONS.getPreferredName(), + private static final ObjectParser<Builder, Void> PARSER = new ObjectParser<>(REGEX_OPTIONS.getPreferredName(), Builder::new); static { PARSER.declareInt(Builder::setMaxDeterminizedStates, MAX_DETERMINIZED_STATES); @@ -66,6 +65,14 @@ public class RegexOptions implements ToXContent, Writeable { PARSER.declareStringOrNull(Builder::setFlags, FLAGS_VALUE); } + public static Builder builder() { + return new Builder(); + } + + static RegexOptions parse(XContentParser parser) throws IOException { + return PARSER.parse(parser, null).build(); + } + private int flagsValue; private int maxDeterminizedStates; @@ -103,14 +110,6 @@ public class RegexOptions implements ToXContent, Writeable { return maxDeterminizedStates; } - public static Builder builder() { - return new Builder(); - } - - static RegexOptions parse(XContentParser parser, ParseFieldMatcherSupplier context) throws IOException { - return PARSER.parse(parser, context).build(); - } - @Override public boolean equals(Object o) { if (this == o) return true; |