incorporate feedback
This commit is contained in:
parent
987f2f5aa8
commit
55c58c56a8
|
@ -63,10 +63,10 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder<CompletionSug
|
||||||
static final ParseField PAYLOAD_FIELD = new ParseField("payload");
|
static final ParseField PAYLOAD_FIELD = new ParseField("payload");
|
||||||
static final ParseField CONTEXTS_FIELD = new ParseField("contexts", "context");
|
static final ParseField CONTEXTS_FIELD = new ParseField("contexts", "context");
|
||||||
|
|
||||||
private static ObjectParser<CompletionSuggestionBuilder, Void> TLP_PARSER =
|
private static ObjectParser<CompletionSuggestionBuilder.InnerBuilder, Void> TLP_PARSER =
|
||||||
new ObjectParser<>(SUGGESTION_NAME, null);
|
new ObjectParser<>(SUGGESTION_NAME, null);
|
||||||
static {
|
static {
|
||||||
TLP_PARSER.declareStringArray(CompletionSuggestionBuilder::payload, PAYLOAD_FIELD);
|
TLP_PARSER.declareStringArray(CompletionSuggestionBuilder.InnerBuilder::payload, PAYLOAD_FIELD);
|
||||||
TLP_PARSER.declareField((parser, completionSuggestionContext, context) -> {
|
TLP_PARSER.declareField((parser, completionSuggestionContext, context) -> {
|
||||||
if (parser.currentToken() == XContentParser.Token.VALUE_BOOLEAN) {
|
if (parser.currentToken() == XContentParser.Token.VALUE_BOOLEAN) {
|
||||||
if (parser.booleanValue()) {
|
if (parser.booleanValue()) {
|
||||||
|
@ -80,10 +80,10 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder<CompletionSug
|
||||||
TLP_PARSER.declareField((parser, completionSuggestionContext, context) ->
|
TLP_PARSER.declareField((parser, completionSuggestionContext, context) ->
|
||||||
completionSuggestionContext.regexOptions = RegexOptions.parse(parser),
|
completionSuggestionContext.regexOptions = RegexOptions.parse(parser),
|
||||||
RegexOptions.REGEX_OPTIONS, ObjectParser.ValueType.OBJECT);
|
RegexOptions.REGEX_OPTIONS, ObjectParser.ValueType.OBJECT);
|
||||||
TLP_PARSER.declareString(CompletionSuggestionBuilder::field, SuggestUtils.Fields.FIELD);
|
TLP_PARSER.declareString(CompletionSuggestionBuilder.InnerBuilder::field, SuggestUtils.Fields.FIELD);
|
||||||
TLP_PARSER.declareString(CompletionSuggestionBuilder::analyzer, SuggestUtils.Fields.ANALYZER);
|
TLP_PARSER.declareString(CompletionSuggestionBuilder.InnerBuilder::analyzer, SuggestUtils.Fields.ANALYZER);
|
||||||
TLP_PARSER.declareInt(CompletionSuggestionBuilder::size, SuggestUtils.Fields.SIZE);
|
TLP_PARSER.declareInt(CompletionSuggestionBuilder.InnerBuilder::size, SuggestUtils.Fields.SIZE);
|
||||||
TLP_PARSER.declareInt(CompletionSuggestionBuilder::shardSize, SuggestUtils.Fields.SHARD_SIZE);
|
TLP_PARSER.declareInt(CompletionSuggestionBuilder.InnerBuilder::shardSize, SuggestUtils.Fields.SHARD_SIZE);
|
||||||
TLP_PARSER.declareField((p, v, c) -> {
|
TLP_PARSER.declareField((p, v, c) -> {
|
||||||
// Copy the current structure. We will parse, once the mapping is provided
|
// Copy the current structure. We will parse, once the mapping is provided
|
||||||
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
|
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
|
||||||
|
@ -93,10 +93,10 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder<CompletionSug
|
||||||
}, CONTEXTS_FIELD, ObjectParser.ValueType.OBJECT); // context is deprecated
|
}, CONTEXTS_FIELD, ObjectParser.ValueType.OBJECT); // context is deprecated
|
||||||
}
|
}
|
||||||
|
|
||||||
private FuzzyOptions fuzzyOptions;
|
protected FuzzyOptions fuzzyOptions;
|
||||||
private RegexOptions regexOptions;
|
protected RegexOptions regexOptions;
|
||||||
private BytesReference contextBytes = null;
|
protected BytesReference contextBytes = null;
|
||||||
private List<String> payloadFields = Collections.emptyList();
|
protected List<String> payloadFields = Collections.emptyList();
|
||||||
|
|
||||||
public CompletionSuggestionBuilder(String fieldname) {
|
public CompletionSuggestionBuilder(String fieldname) {
|
||||||
super(fieldname);
|
super(fieldname);
|
||||||
|
@ -167,6 +167,7 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder<CompletionSug
|
||||||
* Note: Only doc values enabled fields are supported
|
* Note: Only doc values enabled fields are supported
|
||||||
*/
|
*/
|
||||||
public CompletionSuggestionBuilder payload(List<String> fields) {
|
public CompletionSuggestionBuilder payload(List<String> fields) {
|
||||||
|
Objects.requireNonNull(fields, "payload must not be null");
|
||||||
this.payloadFields = fields;
|
this.payloadFields = fields;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -178,6 +179,7 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder<CompletionSug
|
||||||
* and {@link org.elasticsearch.search.suggest.completion.context.GeoQueryContext}
|
* and {@link org.elasticsearch.search.suggest.completion.context.GeoQueryContext}
|
||||||
*/
|
*/
|
||||||
public CompletionSuggestionBuilder contexts(Map<String, List<? extends QueryContext>> queryContexts) {
|
public CompletionSuggestionBuilder contexts(Map<String, List<? extends QueryContext>> queryContexts) {
|
||||||
|
Objects.requireNonNull(queryContexts, "contexts must not be null");
|
||||||
try {
|
try {
|
||||||
XContentBuilder contentBuilder = XContentFactory.jsonBuilder();
|
XContentBuilder contentBuilder = XContentFactory.jsonBuilder();
|
||||||
contentBuilder.startObject();
|
contentBuilder.startObject();
|
||||||
|
@ -196,10 +198,17 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder<CompletionSug
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String field;
|
private static class InnerBuilder extends CompletionSuggestionBuilder {
|
||||||
private CompletionSuggestionBuilder field(String fieldName) {
|
private String field;
|
||||||
this.field = fieldName;
|
|
||||||
return this;
|
public InnerBuilder() {
|
||||||
|
super("_na_");
|
||||||
|
}
|
||||||
|
|
||||||
|
private InnerBuilder field(String fieldName) {
|
||||||
|
this.field = fieldName;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -227,7 +236,7 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder<CompletionSug
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CompletionSuggestionBuilder innerFromXContent(QueryParseContext parseContext) throws IOException {
|
protected CompletionSuggestionBuilder innerFromXContent(QueryParseContext parseContext) throws IOException {
|
||||||
CompletionSuggestionBuilder builder = new CompletionSuggestionBuilder("_na_");
|
CompletionSuggestionBuilder.InnerBuilder builder = new CompletionSuggestionBuilder.InnerBuilder();
|
||||||
TLP_PARSER.parse(parseContext.parser(), builder);
|
TLP_PARSER.parse(parseContext.parser(), builder);
|
||||||
String field = builder.field;
|
String field = builder.field;
|
||||||
// now we should have field name, check and copy fields over to the suggestion builder we return
|
// now we should have field name, check and copy fields over to the suggestion builder we return
|
||||||
|
|
|
@ -140,8 +140,7 @@ public class CompletionSuggesterBuilderTests extends AbstractSuggestionBuilderTe
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
final CompletionSuggestionBuilder builder = builderAndInfo.builder;
|
return new Tuple<>(mapperService, builderAndInfo.builder);
|
||||||
return new Tuple<>(mapperService, builder);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue