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.
This commit is contained in:
parent
ef4db5c1e4
commit
30a788d87c
|
@ -102,7 +102,7 @@ public class RestSearchAction extends BaseRestHandler {
|
|||
* content is read from the request using
|
||||
* RestAction.hasBodyContent.
|
||||
*/
|
||||
public static void parseSearchRequest(SearchRequest searchRequest, IndicesQueriesRegistry indicesQueriesRegistry, RestRequest request,
|
||||
public static void parseSearchRequest(SearchRequest searchRequest, IndicesQueriesRegistry indicesQueriesRegistry, RestRequest request,
|
||||
ParseFieldMatcher parseFieldMatcher, AggregatorParsers aggParsers, BytesReference restContent) throws IOException {
|
||||
if (searchRequest.source() == null) {
|
||||
searchRequest.source(new SearchSourceBuilder());
|
||||
|
@ -256,7 +256,7 @@ public class RestSearchAction extends BaseRestHandler {
|
|||
int suggestSize = request.paramAsInt("suggest_size", 5);
|
||||
String suggestMode = request.param("suggest_mode");
|
||||
searchSourceBuilder.suggest(new SuggestBuilder().addSuggestion(suggestField,
|
||||
termSuggestion().field(suggestField)
|
||||
termSuggestion(suggestField)
|
||||
.text(suggestText).size(suggestSize)
|
||||
.suggestMode(SuggestMode.resolve(suggestMode))));
|
||||
}
|
||||
|
|
|
@ -29,32 +29,32 @@ import org.elasticsearch.search.suggest.term.TermSuggestionBuilder;
|
|||
public abstract class SuggestBuilders {
|
||||
|
||||
/**
|
||||
* Creates a term suggestion lookup query with the provided <code>name</code>
|
||||
* Creates a term suggestion lookup query with the provided <code>fieldname</code>
|
||||
*
|
||||
* @return a {@link org.elasticsearch.search.suggest.term.TermSuggestionBuilder}
|
||||
* instance
|
||||
*/
|
||||
public static TermSuggestionBuilder termSuggestion() {
|
||||
return new TermSuggestionBuilder();
|
||||
public static TermSuggestionBuilder termSuggestion(String fieldname) {
|
||||
return new TermSuggestionBuilder(fieldname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a phrase suggestion lookup query with the provided <code>name</code>
|
||||
* Creates a phrase suggestion lookup query with the provided <code>fieldname</code>
|
||||
*
|
||||
* @return a {@link org.elasticsearch.search.suggest.phrase.PhraseSuggestionBuilder}
|
||||
* instance
|
||||
*/
|
||||
public static PhraseSuggestionBuilder phraseSuggestion() {
|
||||
return new PhraseSuggestionBuilder();
|
||||
public static PhraseSuggestionBuilder phraseSuggestion(String fieldname) {
|
||||
return new PhraseSuggestionBuilder(fieldname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a completion suggestion lookup query with the provided <code>name</code>
|
||||
* Creates a completion suggestion lookup query with the provided <code>fieldname</code>
|
||||
*
|
||||
* @return a {@link org.elasticsearch.search.suggest.completion.CompletionSuggestionBuilder}
|
||||
* instance
|
||||
*/
|
||||
public static CompletionSuggestionBuilder completionSuggestion() {
|
||||
return new CompletionSuggestionBuilder();
|
||||
public static CompletionSuggestionBuilder completionSuggestion(String fieldname) {
|
||||
return new CompletionSuggestionBuilder(fieldname);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.lucene.analysis.Analyzer;
|
|||
import org.elasticsearch.action.support.ToXContentToBytes;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.io.stream.NamedWriteable;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
|
@ -43,8 +44,7 @@ import java.util.Objects;
|
|||
*/
|
||||
public abstract class SuggestionBuilder<T extends SuggestionBuilder<T>> extends ToXContentToBytes implements NamedWriteable<T> {
|
||||
|
||||
// TODO this seems mandatory and should be constructor arg
|
||||
protected String fieldname;
|
||||
protected final String fieldname;
|
||||
protected String text;
|
||||
protected String prefix;
|
||||
protected String regex;
|
||||
|
@ -60,6 +60,31 @@ public abstract class SuggestionBuilder<T extends SuggestionBuilder<T>> extends
|
|||
protected static final ParseField SIZE_FIELD = new ParseField("size");
|
||||
protected static final ParseField SHARDSIZE_FIELD = new ParseField("shard_size");
|
||||
|
||||
/**
|
||||
* Creates a new suggestion.
|
||||
* @param fieldname field to fetch the candidate suggestions from
|
||||
*/
|
||||
public SuggestionBuilder(String fieldname) {
|
||||
Objects.requireNonNull(fieldname, "suggestion requires a field name");
|
||||
if (fieldname.isEmpty()) {
|
||||
throw new IllegalArgumentException("suggestion field name is empty");
|
||||
}
|
||||
this.fieldname = fieldname;
|
||||
}
|
||||
|
||||
/**
|
||||
* internal copy constructor that copies over all class fields from second SuggestionBuilder except field name.
|
||||
*/
|
||||
protected SuggestionBuilder(String fieldname, SuggestionBuilder<?> in) {
|
||||
this(fieldname);
|
||||
text = in.text;
|
||||
prefix = in.prefix;
|
||||
regex = in.regex;
|
||||
analyzer = in.analyzer;
|
||||
size = in.size;
|
||||
shardSize = in.shardSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as in {@link SuggestBuilder#setGlobalText(String)}, but in the suggestion scope.
|
||||
*/
|
||||
|
@ -117,9 +142,7 @@ public abstract class SuggestionBuilder<T extends SuggestionBuilder<T>> extends
|
|||
if (analyzer != null) {
|
||||
builder.field(ANALYZER_FIELD.getPreferredName(), analyzer);
|
||||
}
|
||||
if (fieldname != null) {
|
||||
builder.field(FIELDNAME_FIELD.getPreferredName(), fieldname);
|
||||
}
|
||||
builder.field(FIELDNAME_FIELD.getPreferredName(), fieldname);
|
||||
if (size != null) {
|
||||
builder.field(SIZE_FIELD.getPreferredName(), size);
|
||||
}
|
||||
|
@ -139,7 +162,7 @@ public abstract class SuggestionBuilder<T extends SuggestionBuilder<T>> extends
|
|||
XContentParser parser = parseContext.parser();
|
||||
ParseFieldMatcher parsefieldMatcher = parseContext.parseFieldMatcher();
|
||||
XContentParser.Token token;
|
||||
String fieldName = null;
|
||||
String currentFieldName = null;
|
||||
String suggestText = null;
|
||||
String prefix = null;
|
||||
String regex = null;
|
||||
|
@ -147,21 +170,21 @@ public abstract class SuggestionBuilder<T extends SuggestionBuilder<T>> extends
|
|||
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
fieldName = parser.currentName();
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token.isValue()) {
|
||||
if (parsefieldMatcher.match(fieldName, TEXT_FIELD)) {
|
||||
if (parsefieldMatcher.match(currentFieldName, TEXT_FIELD)) {
|
||||
suggestText = parser.text();
|
||||
} else if (parsefieldMatcher.match(fieldName, PREFIX_FIELD)) {
|
||||
} else if (parsefieldMatcher.match(currentFieldName, PREFIX_FIELD)) {
|
||||
prefix = parser.text();
|
||||
} else if (parsefieldMatcher.match(fieldName, REGEX_FIELD)) {
|
||||
} else if (parsefieldMatcher.match(currentFieldName, REGEX_FIELD)) {
|
||||
regex = parser.text();
|
||||
} else {
|
||||
throw new IllegalArgumentException("[suggestion] does not support [" + fieldName + "]");
|
||||
throw new ParsingException(parser.getTokenLocation(), "suggestion does not support [" + currentFieldName + "]");
|
||||
}
|
||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
SuggestionBuilder<?> suggestParser = suggesters.getSuggestionPrototype(fieldName);
|
||||
SuggestionBuilder<?> suggestParser = suggesters.getSuggestionPrototype(currentFieldName);
|
||||
if (suggestParser == null) {
|
||||
throw new IllegalArgumentException("Suggester[" + fieldName + "] not supported");
|
||||
throw new ParsingException(parser.getTokenLocation(), "suggestion [" + currentFieldName + "] not supported");
|
||||
}
|
||||
suggestionBuilder = suggestParser.innerFromXContent(parseContext);
|
||||
}
|
||||
|
@ -182,10 +205,6 @@ public abstract class SuggestionBuilder<T extends SuggestionBuilder<T>> extends
|
|||
|
||||
public SuggestionContext build(QueryShardContext context) throws IOException {
|
||||
SuggestionContext suggestionContext = innerBuild(context);
|
||||
// TODO make field mandatory in the builder, then remove this
|
||||
if (suggestionContext.getField() == null) {
|
||||
throw new IllegalArgumentException("The required field option is missing");
|
||||
}
|
||||
return suggestionContext;
|
||||
}
|
||||
|
||||
|
@ -254,20 +273,6 @@ public abstract class SuggestionBuilder<T extends SuggestionBuilder<T>> extends
|
|||
return getWriteableName();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets from what field to fetch the candidate suggestions from. This is an
|
||||
* required option and needs to be set via this setter or
|
||||
* {@link org.elasticsearch.search.suggest.term.TermSuggestionBuilder#field(String)}
|
||||
* method
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public T field(String field) {
|
||||
Objects.requireNonNull(field, "fieldname must not be null");
|
||||
this.fieldname = field;
|
||||
return (T)this;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the {@link #field()} parameter
|
||||
*/
|
||||
|
@ -298,7 +303,7 @@ public abstract class SuggestionBuilder<T extends SuggestionBuilder<T>> extends
|
|||
@SuppressWarnings("unchecked")
|
||||
public T size(int size) {
|
||||
if (size <= 0) {
|
||||
throw new IllegalArgumentException("Size must be positive");
|
||||
throw new IllegalArgumentException("size must be positive");
|
||||
}
|
||||
this.size = size;
|
||||
return (T)this;
|
||||
|
@ -339,8 +344,8 @@ public abstract class SuggestionBuilder<T extends SuggestionBuilder<T>> extends
|
|||
|
||||
@Override
|
||||
public final T readFrom(StreamInput in) throws IOException {
|
||||
T suggestionBuilder = doReadFrom(in);
|
||||
suggestionBuilder.fieldname = in.readOptionalString();
|
||||
String fieldname = in.readString();
|
||||
T suggestionBuilder = doReadFrom(in, fieldname);
|
||||
suggestionBuilder.text = in.readOptionalString();
|
||||
suggestionBuilder.prefix = in.readOptionalString();
|
||||
suggestionBuilder.regex = in.readOptionalString();
|
||||
|
@ -353,13 +358,14 @@ public abstract class SuggestionBuilder<T extends SuggestionBuilder<T>> extends
|
|||
/**
|
||||
* Subclass should return a new instance, reading itself from the input string
|
||||
* @param in the input string to read from
|
||||
* @param fieldname the fieldname needed for ctor or concrete suggestion
|
||||
*/
|
||||
protected abstract T doReadFrom(StreamInput in) throws IOException;
|
||||
protected abstract T doReadFrom(StreamInput in, String fieldname) throws IOException;
|
||||
|
||||
@Override
|
||||
public final void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeString(fieldname);
|
||||
doWriteTo(out);
|
||||
out.writeOptionalString(fieldname);
|
||||
out.writeOptionalString(text);
|
||||
out.writeOptionalString(prefix);
|
||||
out.writeOptionalString(regex);
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.search.suggest.phrase;
|
|||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.io.stream.Writeable;
|
||||
|
@ -54,11 +55,11 @@ import java.util.Set;
|
|||
/**
|
||||
* Defines the actual suggest command for phrase suggestions ( <tt>phrase</tt>).
|
||||
*/
|
||||
public final class PhraseSuggestionBuilder extends SuggestionBuilder<PhraseSuggestionBuilder> {
|
||||
public class PhraseSuggestionBuilder extends SuggestionBuilder<PhraseSuggestionBuilder> {
|
||||
|
||||
private static final String SUGGESTION_NAME = "phrase";
|
||||
|
||||
public static final PhraseSuggestionBuilder PROTOTYPE = new PhraseSuggestionBuilder();
|
||||
public static final PhraseSuggestionBuilder PROTOTYPE = new PhraseSuggestionBuilder("_na_");
|
||||
|
||||
protected static final ParseField MAXERRORS_FIELD = new ParseField("max_errors");
|
||||
protected static final ParseField RWE_LIKELIHOOD_FIELD = new ParseField("real_word_error_likelihood");
|
||||
|
@ -93,6 +94,32 @@ public final class PhraseSuggestionBuilder extends SuggestionBuilder<PhraseSugge
|
|||
private SmoothingModel model;
|
||||
private final Map<String, List<CandidateGenerator>> generators = new HashMap<>();
|
||||
|
||||
public PhraseSuggestionBuilder(String fieldname) {
|
||||
super(fieldname);
|
||||
}
|
||||
|
||||
/**
|
||||
* internal copy constructor that copies over all class fields except for the fieldname which is
|
||||
* set to the one provided in the first argument
|
||||
*/
|
||||
private PhraseSuggestionBuilder(String fieldname, PhraseSuggestionBuilder in) {
|
||||
super(fieldname, in);
|
||||
maxErrors = in.maxErrors;
|
||||
separator = in.separator;
|
||||
realWordErrorLikelihood = in.realWordErrorLikelihood;
|
||||
confidence = in.confidence;
|
||||
gramSize = in.gramSize;
|
||||
forceUnigrams = in.forceUnigrams;
|
||||
tokenLimit = in.tokenLimit;
|
||||
preTag = in.preTag;
|
||||
postTag = in.postTag;
|
||||
collateQuery = in.collateQuery;
|
||||
collateParams = in.collateParams;
|
||||
collatePrune = in.collatePrune;
|
||||
model = in.model;
|
||||
generators.putAll(in.generators);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the gram size for the n-gram model used for this suggester. The
|
||||
* default value is <tt>1</tt> corresponding to <tt>unigrams</tt>. Use
|
||||
|
@ -395,102 +422,114 @@ public final class PhraseSuggestionBuilder extends SuggestionBuilder<PhraseSugge
|
|||
@Override
|
||||
protected PhraseSuggestionBuilder innerFromXContent(QueryParseContext parseContext) throws IOException {
|
||||
XContentParser parser = parseContext.parser();
|
||||
PhraseSuggestionBuilder suggestion = new PhraseSuggestionBuilder();
|
||||
PhraseSuggestionBuilder tmpSuggestion = new PhraseSuggestionBuilder("_na_");
|
||||
ParseFieldMatcher parseFieldMatcher = parseContext.parseFieldMatcher();
|
||||
XContentParser.Token token;
|
||||
String fieldName = null;
|
||||
String currentFieldName = null;
|
||||
String fieldname = null;
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
fieldName = parser.currentName();
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token.isValue()) {
|
||||
if (parseFieldMatcher.match(fieldName, SuggestionBuilder.ANALYZER_FIELD)) {
|
||||
suggestion.analyzer(parser.text());
|
||||
} else if (parseFieldMatcher.match(fieldName, SuggestionBuilder.FIELDNAME_FIELD)) {
|
||||
suggestion.field(parser.text());
|
||||
} else if (parseFieldMatcher.match(fieldName, SuggestionBuilder.SIZE_FIELD)) {
|
||||
suggestion.size(parser.intValue());
|
||||
} else if (parseFieldMatcher.match(fieldName, SuggestionBuilder.SHARDSIZE_FIELD)) {
|
||||
suggestion.shardSize(parser.intValue());
|
||||
} else if (parseFieldMatcher.match(fieldName, PhraseSuggestionBuilder.RWE_LIKELIHOOD_FIELD)) {
|
||||
suggestion.realWordErrorLikelihood(parser.floatValue());
|
||||
} else if (parseFieldMatcher.match(fieldName, PhraseSuggestionBuilder.CONFIDENCE_FIELD)) {
|
||||
suggestion.confidence(parser.floatValue());
|
||||
} else if (parseFieldMatcher.match(fieldName, PhraseSuggestionBuilder.SEPARATOR_FIELD)) {
|
||||
suggestion.separator(parser.text());
|
||||
} else if (parseFieldMatcher.match(fieldName, PhraseSuggestionBuilder.MAXERRORS_FIELD)) {
|
||||
suggestion.maxErrors(parser.floatValue());
|
||||
} else if (parseFieldMatcher.match(fieldName, PhraseSuggestionBuilder.GRAMSIZE_FIELD)) {
|
||||
suggestion.gramSize(parser.intValue());
|
||||
} else if (parseFieldMatcher.match(fieldName, PhraseSuggestionBuilder.FORCE_UNIGRAM_FIELD)) {
|
||||
suggestion.forceUnigrams(parser.booleanValue());
|
||||
} else if (parseFieldMatcher.match(fieldName, PhraseSuggestionBuilder.TOKEN_LIMIT_FIELD)) {
|
||||
suggestion.tokenLimit(parser.intValue());
|
||||
if (parseFieldMatcher.match(currentFieldName, SuggestionBuilder.ANALYZER_FIELD)) {
|
||||
tmpSuggestion.analyzer(parser.text());
|
||||
} else if (parseFieldMatcher.match(currentFieldName, SuggestionBuilder.FIELDNAME_FIELD)) {
|
||||
fieldname = parser.text();
|
||||
} else if (parseFieldMatcher.match(currentFieldName, SuggestionBuilder.SIZE_FIELD)) {
|
||||
tmpSuggestion.size(parser.intValue());
|
||||
} else if (parseFieldMatcher.match(currentFieldName, SuggestionBuilder.SHARDSIZE_FIELD)) {
|
||||
tmpSuggestion.shardSize(parser.intValue());
|
||||
} else if (parseFieldMatcher.match(currentFieldName, PhraseSuggestionBuilder.RWE_LIKELIHOOD_FIELD)) {
|
||||
tmpSuggestion.realWordErrorLikelihood(parser.floatValue());
|
||||
} else if (parseFieldMatcher.match(currentFieldName, PhraseSuggestionBuilder.CONFIDENCE_FIELD)) {
|
||||
tmpSuggestion.confidence(parser.floatValue());
|
||||
} else if (parseFieldMatcher.match(currentFieldName, PhraseSuggestionBuilder.SEPARATOR_FIELD)) {
|
||||
tmpSuggestion.separator(parser.text());
|
||||
} else if (parseFieldMatcher.match(currentFieldName, PhraseSuggestionBuilder.MAXERRORS_FIELD)) {
|
||||
tmpSuggestion.maxErrors(parser.floatValue());
|
||||
} else if (parseFieldMatcher.match(currentFieldName, PhraseSuggestionBuilder.GRAMSIZE_FIELD)) {
|
||||
tmpSuggestion.gramSize(parser.intValue());
|
||||
} else if (parseFieldMatcher.match(currentFieldName, PhraseSuggestionBuilder.FORCE_UNIGRAM_FIELD)) {
|
||||
tmpSuggestion.forceUnigrams(parser.booleanValue());
|
||||
} else if (parseFieldMatcher.match(currentFieldName, PhraseSuggestionBuilder.TOKEN_LIMIT_FIELD)) {
|
||||
tmpSuggestion.tokenLimit(parser.intValue());
|
||||
} else {
|
||||
throw new IllegalArgumentException("suggester[phrase] doesn't support field [" + fieldName + "]");
|
||||
throw new ParsingException(parser.getTokenLocation(),
|
||||
"suggester[phrase] doesn't support field [" + currentFieldName + "]");
|
||||
}
|
||||
} else if (token == Token.START_ARRAY) {
|
||||
if (parseFieldMatcher.match(fieldName, DirectCandidateGeneratorBuilder.DIRECT_GENERATOR_FIELD)) {
|
||||
if (parseFieldMatcher.match(currentFieldName, DirectCandidateGeneratorBuilder.DIRECT_GENERATOR_FIELD)) {
|
||||
// for now we only have a single type of generators
|
||||
while ((token = parser.nextToken()) == Token.START_OBJECT) {
|
||||
suggestion.addCandidateGenerator(DirectCandidateGeneratorBuilder.PROTOTYPE.fromXContent(parseContext));
|
||||
tmpSuggestion.addCandidateGenerator(DirectCandidateGeneratorBuilder.PROTOTYPE.fromXContent(parseContext));
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("suggester[phrase] doesn't support array field [" + fieldName + "]");
|
||||
throw new ParsingException(parser.getTokenLocation(),
|
||||
"suggester[phrase] doesn't support array field [" + currentFieldName + "]");
|
||||
}
|
||||
} else if (token == Token.START_OBJECT) {
|
||||
if (parseFieldMatcher.match(fieldName, PhraseSuggestionBuilder.SMOOTHING_MODEL_FIELD)) {
|
||||
ensureNoSmoothing(suggestion);
|
||||
suggestion.smoothingModel(SmoothingModel.fromXContent(parseContext));
|
||||
} else if (parseFieldMatcher.match(fieldName, PhraseSuggestionBuilder.HIGHLIGHT_FIELD)) {
|
||||
if (parseFieldMatcher.match(currentFieldName, PhraseSuggestionBuilder.SMOOTHING_MODEL_FIELD)) {
|
||||
ensureNoSmoothing(tmpSuggestion);
|
||||
tmpSuggestion.smoothingModel(SmoothingModel.fromXContent(parseContext));
|
||||
} else if (parseFieldMatcher.match(currentFieldName, PhraseSuggestionBuilder.HIGHLIGHT_FIELD)) {
|
||||
String preTag = null;
|
||||
String postTag = null;
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
fieldName = parser.currentName();
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token.isValue()) {
|
||||
if (parseFieldMatcher.match(fieldName, PhraseSuggestionBuilder.PRE_TAG_FIELD)) {
|
||||
if (parseFieldMatcher.match(currentFieldName, PhraseSuggestionBuilder.PRE_TAG_FIELD)) {
|
||||
preTag = parser.text();
|
||||
} else if (parseFieldMatcher.match(fieldName, PhraseSuggestionBuilder.POST_TAG_FIELD)) {
|
||||
} else if (parseFieldMatcher.match(currentFieldName, PhraseSuggestionBuilder.POST_TAG_FIELD)) {
|
||||
postTag = parser.text();
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"suggester[phrase][highlight] doesn't support field [" + fieldName + "]");
|
||||
throw new ParsingException(parser.getTokenLocation(),
|
||||
"suggester[phrase][highlight] doesn't support field [" + currentFieldName + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
suggestion.highlight(preTag, postTag);
|
||||
} else if (parseFieldMatcher.match(fieldName, PhraseSuggestionBuilder.COLLATE_FIELD)) {
|
||||
tmpSuggestion.highlight(preTag, postTag);
|
||||
} else if (parseFieldMatcher.match(currentFieldName, PhraseSuggestionBuilder.COLLATE_FIELD)) {
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
fieldName = parser.currentName();
|
||||
} else if (parseFieldMatcher.match(fieldName, PhraseSuggestionBuilder.COLLATE_QUERY_FIELD)) {
|
||||
if (suggestion.collateQuery() != null) {
|
||||
throw new IllegalArgumentException(
|
||||
"suggester[phrase][collate] query already set, doesn't support additional [" + fieldName + "]");
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (parseFieldMatcher.match(currentFieldName, PhraseSuggestionBuilder.COLLATE_QUERY_FIELD)) {
|
||||
if (tmpSuggestion.collateQuery() != null) {
|
||||
throw new ParsingException(parser.getTokenLocation(),
|
||||
"suggester[phrase][collate] query already set, doesn't support additional ["
|
||||
+ currentFieldName + "]");
|
||||
}
|
||||
Template template = Template.parse(parser, parseFieldMatcher);
|
||||
suggestion.collateQuery(template);
|
||||
} else if (parseFieldMatcher.match(fieldName, PhraseSuggestionBuilder.COLLATE_QUERY_PARAMS)) {
|
||||
suggestion.collateParams(parser.map());
|
||||
} else if (parseFieldMatcher.match(fieldName, PhraseSuggestionBuilder.COLLATE_QUERY_PRUNE)) {
|
||||
tmpSuggestion.collateQuery(template);
|
||||
} else if (parseFieldMatcher.match(currentFieldName, PhraseSuggestionBuilder.COLLATE_QUERY_PARAMS)) {
|
||||
tmpSuggestion.collateParams(parser.map());
|
||||
} else if (parseFieldMatcher.match(currentFieldName, PhraseSuggestionBuilder.COLLATE_QUERY_PRUNE)) {
|
||||
if (parser.isBooleanValue()) {
|
||||
suggestion.collatePrune(parser.booleanValue());
|
||||
tmpSuggestion.collatePrune(parser.booleanValue());
|
||||
} else {
|
||||
throw new IllegalArgumentException("suggester[phrase][collate] prune must be either 'true' or 'false'");
|
||||
throw new ParsingException(parser.getTokenLocation(),
|
||||
"suggester[phrase][collate] prune must be either 'true' or 'false'");
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"suggester[phrase][collate] doesn't support field [" + fieldName + "]");
|
||||
throw new ParsingException(parser.getTokenLocation(),
|
||||
"suggester[phrase][collate] doesn't support field [" + currentFieldName + "]");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("suggester[phrase] doesn't support array field [" + fieldName + "]");
|
||||
throw new ParsingException(parser.getTokenLocation(),
|
||||
"suggester[phrase] doesn't support array field [" + currentFieldName + "]");
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("suggester[phrase] doesn't support field [" + fieldName + "]");
|
||||
throw new ParsingException(parser.getTokenLocation(),
|
||||
"suggester[phrase] doesn't support field [" + currentFieldName + "]");
|
||||
}
|
||||
}
|
||||
return suggestion;
|
||||
|
||||
// now we should have field name, check and copy fields over to the suggestion builder we return
|
||||
if (fieldname == null) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "the required field option is missing");
|
||||
}
|
||||
return new PhraseSuggestionBuilder(fieldname, tmpSuggestion);
|
||||
}
|
||||
|
||||
|
||||
|
@ -616,8 +655,8 @@ public final class PhraseSuggestionBuilder extends SuggestionBuilder<PhraseSugge
|
|||
}
|
||||
|
||||
@Override
|
||||
public PhraseSuggestionBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
PhraseSuggestionBuilder builder = new PhraseSuggestionBuilder();
|
||||
public PhraseSuggestionBuilder doReadFrom(StreamInput in, String fieldname) throws IOException {
|
||||
PhraseSuggestionBuilder builder = new PhraseSuggestionBuilder(fieldname);
|
||||
builder.maxErrors = in.readFloat();
|
||||
builder.realWordErrorLikelihood = in.readFloat();
|
||||
builder.confidence = in.readFloat();
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.apache.lucene.search.spell.LuceneLevenshteinDistance;
|
|||
import org.apache.lucene.search.spell.NGramDistance;
|
||||
import org.apache.lucene.search.spell.StringDistance;
|
||||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.io.stream.Writeable;
|
||||
|
@ -67,19 +68,40 @@ import static org.elasticsearch.search.suggest.SuggestUtils.Fields.SUGGEST_MODE;
|
|||
*/
|
||||
public class TermSuggestionBuilder extends SuggestionBuilder<TermSuggestionBuilder> {
|
||||
|
||||
public static final TermSuggestionBuilder PROTOTYPE = new TermSuggestionBuilder();
|
||||
public static final TermSuggestionBuilder PROTOTYPE = new TermSuggestionBuilder("_na_");
|
||||
private static final String SUGGESTION_NAME = "term";
|
||||
|
||||
private SuggestMode suggestMode = SuggestMode.MISSING;
|
||||
private Float accuracy = DEFAULT_ACCURACY;
|
||||
private float accuracy = DEFAULT_ACCURACY;
|
||||
private SortBy sort = SortBy.SCORE;
|
||||
private StringDistanceImpl stringDistance = StringDistanceImpl.INTERNAL;
|
||||
private Integer maxEdits = DEFAULT_MAX_EDITS;
|
||||
private Integer maxInspections = DEFAULT_MAX_INSPECTIONS;
|
||||
private Float maxTermFreq = DEFAULT_MAX_TERM_FREQ;
|
||||
private Integer prefixLength = DEFAULT_PREFIX_LENGTH;
|
||||
private Integer minWordLength = DEFAULT_MIN_WORD_LENGTH;
|
||||
private Float minDocFreq = DEFAULT_MIN_DOC_FREQ;
|
||||
private int maxEdits = DEFAULT_MAX_EDITS;
|
||||
private int maxInspections = DEFAULT_MAX_INSPECTIONS;
|
||||
private float maxTermFreq = DEFAULT_MAX_TERM_FREQ;
|
||||
private int prefixLength = DEFAULT_PREFIX_LENGTH;
|
||||
private int minWordLength = DEFAULT_MIN_WORD_LENGTH;
|
||||
private float minDocFreq = DEFAULT_MIN_DOC_FREQ;
|
||||
|
||||
public TermSuggestionBuilder(String fieldname) {
|
||||
super(fieldname);
|
||||
}
|
||||
|
||||
/**
|
||||
* internal copy constructor that copies over all class field except fieldname.
|
||||
*/
|
||||
private TermSuggestionBuilder(String fieldname, TermSuggestionBuilder in) {
|
||||
super(fieldname, in);
|
||||
suggestMode = in.suggestMode;
|
||||
accuracy = in.accuracy;
|
||||
sort = in.sort;
|
||||
stringDistance = in.stringDistance;
|
||||
maxEdits = in.maxEdits;
|
||||
maxInspections = in.maxInspections;
|
||||
maxTermFreq = in.maxTermFreq;
|
||||
prefixLength = in.prefixLength;
|
||||
minWordLength = in.minWordLength;
|
||||
minDocFreq = in.minDocFreq;
|
||||
}
|
||||
|
||||
/**
|
||||
* The global suggest mode controls what suggested terms are included or
|
||||
|
@ -126,7 +148,7 @@ public class TermSuggestionBuilder extends SuggestionBuilder<TermSuggestionBuild
|
|||
/**
|
||||
* Get the accuracy setting.
|
||||
*/
|
||||
public Float accuracy() {
|
||||
public float accuracy() {
|
||||
return accuracy;
|
||||
}
|
||||
|
||||
|
@ -202,7 +224,7 @@ public class TermSuggestionBuilder extends SuggestionBuilder<TermSuggestionBuild
|
|||
/**
|
||||
* Get the maximum edit distance setting.
|
||||
*/
|
||||
public Integer maxEdits() {
|
||||
public int maxEdits() {
|
||||
return maxEdits;
|
||||
}
|
||||
|
||||
|
@ -222,7 +244,7 @@ public class TermSuggestionBuilder extends SuggestionBuilder<TermSuggestionBuild
|
|||
/**
|
||||
* Get the factor for inspecting more candidate suggestions setting.
|
||||
*/
|
||||
public Integer maxInspections() {
|
||||
public int maxInspections() {
|
||||
return maxInspections;
|
||||
}
|
||||
|
||||
|
@ -251,7 +273,7 @@ public class TermSuggestionBuilder extends SuggestionBuilder<TermSuggestionBuild
|
|||
/**
|
||||
* Get the maximum term frequency threshold setting.
|
||||
*/
|
||||
public Float maxTermFreq() {
|
||||
public float maxTermFreq() {
|
||||
return maxTermFreq;
|
||||
}
|
||||
|
||||
|
@ -272,7 +294,7 @@ public class TermSuggestionBuilder extends SuggestionBuilder<TermSuggestionBuild
|
|||
/**
|
||||
* Get the minimum prefix length that must match setting.
|
||||
*/
|
||||
public Integer prefixLength() {
|
||||
public int prefixLength() {
|
||||
return prefixLength;
|
||||
}
|
||||
|
||||
|
@ -291,7 +313,7 @@ public class TermSuggestionBuilder extends SuggestionBuilder<TermSuggestionBuild
|
|||
/**
|
||||
* Get the minimum length of a text term to be corrected setting.
|
||||
*/
|
||||
public Integer minWordLength() {
|
||||
public int minWordLength() {
|
||||
return minWordLength;
|
||||
}
|
||||
|
||||
|
@ -317,7 +339,7 @@ public class TermSuggestionBuilder extends SuggestionBuilder<TermSuggestionBuild
|
|||
* Get the minimal threshold for the frequency of a term appearing in the
|
||||
* document set setting.
|
||||
*/
|
||||
public Float minDocFreq() {
|
||||
public float minDocFreq() {
|
||||
return minDocFreq;
|
||||
}
|
||||
|
||||
|
@ -339,48 +361,54 @@ public class TermSuggestionBuilder extends SuggestionBuilder<TermSuggestionBuild
|
|||
@Override
|
||||
protected TermSuggestionBuilder innerFromXContent(QueryParseContext parseContext) throws IOException {
|
||||
XContentParser parser = parseContext.parser();
|
||||
TermSuggestionBuilder suggestion = new TermSuggestionBuilder();
|
||||
TermSuggestionBuilder tmpSuggestion = new TermSuggestionBuilder("_na_");
|
||||
ParseFieldMatcher parseFieldMatcher = parseContext.parseFieldMatcher();
|
||||
XContentParser.Token token;
|
||||
String fieldName = null;
|
||||
String currentFieldName = null;
|
||||
String fieldname = null;
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
fieldName = parser.currentName();
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token.isValue()) {
|
||||
if (parseFieldMatcher.match(fieldName, SuggestionBuilder.ANALYZER_FIELD)) {
|
||||
suggestion.analyzer(parser.text());
|
||||
} else if (parseFieldMatcher.match(fieldName, SuggestionBuilder.FIELDNAME_FIELD)) {
|
||||
suggestion.field(parser.text());
|
||||
} else if (parseFieldMatcher.match(fieldName, SuggestionBuilder.SIZE_FIELD)) {
|
||||
suggestion.size(parser.intValue());
|
||||
} else if (parseFieldMatcher.match(fieldName, SuggestionBuilder.SHARDSIZE_FIELD)) {
|
||||
suggestion.shardSize(parser.intValue());
|
||||
} else if (parseFieldMatcher.match(fieldName, SUGGEST_MODE)) {
|
||||
suggestion.suggestMode(SuggestMode.resolve(parser.text()));
|
||||
} else if (parseFieldMatcher.match(fieldName, ACCURACY)) {
|
||||
suggestion.accuracy(parser.floatValue());
|
||||
} else if (parseFieldMatcher.match(fieldName, SORT)) {
|
||||
suggestion.sort(SortBy.resolve(parser.text()));
|
||||
} else if (parseFieldMatcher.match(fieldName, STRING_DISTANCE)) {
|
||||
suggestion.stringDistance(StringDistanceImpl.resolve(parser.text()));
|
||||
} else if (parseFieldMatcher.match(fieldName, MAX_EDITS)) {
|
||||
suggestion.maxEdits(parser.intValue());
|
||||
} else if (parseFieldMatcher.match(fieldName, MAX_INSPECTIONS)) {
|
||||
suggestion.maxInspections(parser.intValue());
|
||||
} else if (parseFieldMatcher.match(fieldName, MAX_TERM_FREQ)) {
|
||||
suggestion.maxTermFreq(parser.floatValue());
|
||||
} else if (parseFieldMatcher.match(fieldName, PREFIX_LENGTH)) {
|
||||
suggestion.prefixLength(parser.intValue());
|
||||
} else if (parseFieldMatcher.match(fieldName, MIN_WORD_LENGTH)) {
|
||||
suggestion.minWordLength(parser.intValue());
|
||||
} else if (parseFieldMatcher.match(fieldName, MIN_DOC_FREQ)) {
|
||||
suggestion.minDocFreq(parser.floatValue());
|
||||
if (parseFieldMatcher.match(currentFieldName, SuggestionBuilder.ANALYZER_FIELD)) {
|
||||
tmpSuggestion.analyzer(parser.text());
|
||||
} else if (parseFieldMatcher.match(currentFieldName, SuggestionBuilder.FIELDNAME_FIELD)) {
|
||||
fieldname = parser.text();
|
||||
} else if (parseFieldMatcher.match(currentFieldName, SuggestionBuilder.SIZE_FIELD)) {
|
||||
tmpSuggestion.size(parser.intValue());
|
||||
} else if (parseFieldMatcher.match(currentFieldName, SuggestionBuilder.SHARDSIZE_FIELD)) {
|
||||
tmpSuggestion.shardSize(parser.intValue());
|
||||
} else if (parseFieldMatcher.match(currentFieldName, SUGGEST_MODE)) {
|
||||
tmpSuggestion.suggestMode(SuggestMode.resolve(parser.text()));
|
||||
} else if (parseFieldMatcher.match(currentFieldName, ACCURACY)) {
|
||||
tmpSuggestion.accuracy(parser.floatValue());
|
||||
} else if (parseFieldMatcher.match(currentFieldName, SORT)) {
|
||||
tmpSuggestion.sort(SortBy.resolve(parser.text()));
|
||||
} else if (parseFieldMatcher.match(currentFieldName, STRING_DISTANCE)) {
|
||||
tmpSuggestion.stringDistance(StringDistanceImpl.resolve(parser.text()));
|
||||
} else if (parseFieldMatcher.match(currentFieldName, MAX_EDITS)) {
|
||||
tmpSuggestion.maxEdits(parser.intValue());
|
||||
} else if (parseFieldMatcher.match(currentFieldName, MAX_INSPECTIONS)) {
|
||||
tmpSuggestion.maxInspections(parser.intValue());
|
||||
} else if (parseFieldMatcher.match(currentFieldName, MAX_TERM_FREQ)) {
|
||||
tmpSuggestion.maxTermFreq(parser.floatValue());
|
||||
} else if (parseFieldMatcher.match(currentFieldName, PREFIX_LENGTH)) {
|
||||
tmpSuggestion.prefixLength(parser.intValue());
|
||||
} else if (parseFieldMatcher.match(currentFieldName, MIN_WORD_LENGTH)) {
|
||||
tmpSuggestion.minWordLength(parser.intValue());
|
||||
} else if (parseFieldMatcher.match(currentFieldName, MIN_DOC_FREQ)) {
|
||||
tmpSuggestion.minDocFreq(parser.floatValue());
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("suggester[term] doesn't support field [" + fieldName + "]");
|
||||
throw new ParsingException(parser.getTokenLocation(), "suggester[term] doesn't support field [" + currentFieldName + "]");
|
||||
}
|
||||
}
|
||||
return suggestion;
|
||||
|
||||
// now we should have field name, check and copy fields over to the suggestion builder we return
|
||||
if (fieldname == null) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "the required field option is missing");
|
||||
}
|
||||
return new TermSuggestionBuilder(fieldname, tmpSuggestion);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -423,8 +451,8 @@ public class TermSuggestionBuilder extends SuggestionBuilder<TermSuggestionBuild
|
|||
}
|
||||
|
||||
@Override
|
||||
public TermSuggestionBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
TermSuggestionBuilder builder = new TermSuggestionBuilder();
|
||||
public TermSuggestionBuilder doReadFrom(StreamInput in, String fieldname) throws IOException {
|
||||
TermSuggestionBuilder builder = new TermSuggestionBuilder(fieldname);
|
||||
builder.suggestMode = SuggestMode.PROTOTYPE.readFrom(in);
|
||||
builder.accuracy = in.readFloat();
|
||||
builder.sort = SortBy.PROTOTYPE.readFrom(in);
|
||||
|
|
|
@ -139,9 +139,9 @@ public class SuggestStatsIT extends ESIntegTestCase {
|
|||
private SuggestRequestBuilder addSuggestions(SuggestRequestBuilder request, int i) {
|
||||
for (int s = 0; s < randomIntBetween(2, 10); s++) {
|
||||
if (randomBoolean()) {
|
||||
request.addSuggestion("s" + s, new PhraseSuggestionBuilder().field("f").text("test" + i + " test" + (i - 1)));
|
||||
request.addSuggestion("s" + s, new PhraseSuggestionBuilder("f").text("test" + i + " test" + (i - 1)));
|
||||
} else {
|
||||
request.addSuggestion("s" + s, new TermSuggestionBuilder().field("f").text("test" + i));
|
||||
request.addSuggestion("s" + s, new TermSuggestionBuilder("f").text("test" + i));
|
||||
}
|
||||
}
|
||||
return request;
|
||||
|
|
|
@ -749,7 +749,7 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
private static SuggestRequestBuilder suggest(String... indices) {
|
||||
return client().prepareSuggest(indices).addSuggestion("name", SuggestBuilders.termSuggestion().field("a"));
|
||||
return client().prepareSuggest(indices).addSuggestion("name", SuggestBuilders.termSuggestion("a"));
|
||||
}
|
||||
|
||||
private static GetAliasesRequestBuilder getAliases(String... indices) {
|
||||
|
|
|
@ -412,7 +412,7 @@ public class SearchSourceBuilderTests extends ESTestCase {
|
|||
// NORELEASE need a random suggest builder method
|
||||
builder.suggest(new SuggestBuilder().setGlobalText(randomAsciiOfLengthBetween(1, 5)).addSuggestion(
|
||||
randomAsciiOfLengthBetween(1, 5),
|
||||
SuggestBuilders.termSuggestion()));
|
||||
SuggestBuilders.termSuggestion(randomAsciiOfLengthBetween(1, 5))));
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
// NORELEASE need a random inner hits builder method
|
||||
|
|
|
@ -135,7 +135,6 @@ public abstract class AbstractSuggestionBuilderTestCase<SB extends SuggestionBui
|
|||
*/
|
||||
protected SB randomTestBuilder() {
|
||||
SB randomSuggestion = randomSuggestionBuilder();
|
||||
randomSuggestion.field(randomAsciiOfLengthBetween(2, 20));
|
||||
maybeSet(randomSuggestion::text, randomAsciiOfLengthBetween(2, 20));
|
||||
maybeSet(randomSuggestion::prefix, randomAsciiOfLengthBetween(2, 20));
|
||||
maybeSet(randomSuggestion::regex, randomAsciiOfLengthBetween(2, 20));
|
||||
|
@ -309,9 +308,9 @@ public abstract class AbstractSuggestionBuilderTestCase<SB extends SuggestionBui
|
|||
private SB mutate(SB firstBuilder) throws IOException {
|
||||
SB mutation = serializedCopy(firstBuilder);
|
||||
assertNotSame(mutation, firstBuilder);
|
||||
// change ither one of the shared SuggestionBuilder parameters, or delegate to the specific tests mutate method
|
||||
if (randomBoolean()) {
|
||||
// change one of the common SuggestionBuilder parameters
|
||||
switch (randomIntBetween(0, 6)) {
|
||||
switch (randomIntBetween(0, 5)) {
|
||||
case 0:
|
||||
mutation.text(randomValueOtherThan(mutation.text(), () -> randomAsciiOfLengthBetween(2, 20)));
|
||||
break;
|
||||
|
@ -322,15 +321,12 @@ public abstract class AbstractSuggestionBuilderTestCase<SB extends SuggestionBui
|
|||
mutation.regex(randomValueOtherThan(mutation.regex(), () -> randomAsciiOfLengthBetween(2, 20)));
|
||||
break;
|
||||
case 3:
|
||||
mutation.field(randomValueOtherThan(mutation.field(), () -> randomAsciiOfLengthBetween(2, 20)));
|
||||
break;
|
||||
case 4:
|
||||
mutation.analyzer(randomValueOtherThan(mutation.analyzer(), () -> randomAsciiOfLengthBetween(2, 20)));
|
||||
break;
|
||||
case 5:
|
||||
case 4:
|
||||
mutation.size(randomValueOtherThan(mutation.size(), () -> randomIntBetween(1, 20)));
|
||||
break;
|
||||
case 6:
|
||||
case 5:
|
||||
mutation.shardSize(randomValueOtherThan(mutation.shardSize(), () -> randomIntBetween(1, 20)));
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
));
|
||||
}
|
||||
indexRandom(true, indexRequestBuilders);
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg");
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg");
|
||||
assertSuggestions("foo", prefix, "suggestion10", "suggestion9", "suggestion8", "suggestion7", "suggestion6");
|
||||
}
|
||||
|
||||
|
@ -126,7 +126,7 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
));
|
||||
}
|
||||
indexRandom(true, indexRequestBuilders);
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion().field(FIELD).regex("sugg.*es");
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).regex("sugg.*es");
|
||||
assertSuggestions("foo", prefix, "sugg10estion", "sugg9estion", "sugg8estion", "sugg7estion", "sugg6estion");
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,7 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
));
|
||||
}
|
||||
indexRandom(true, indexRequestBuilders);
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg", Fuzziness.ONE);
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg", Fuzziness.ONE);
|
||||
assertSuggestions("foo", prefix, "sugxgestion10", "sugxgestion9", "sugxgestion8", "sugxgestion7", "sugxgestion6");
|
||||
}
|
||||
|
||||
|
@ -173,13 +173,13 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
for (int i = 0; i < size; i++) {
|
||||
outputs[i] = "suggestion" + (numDocs - i);
|
||||
}
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sug").size(size);
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sug").size(size);
|
||||
assertSuggestions("foo", prefix, outputs);
|
||||
|
||||
CompletionSuggestionBuilder regex = SuggestBuilders.completionSuggestion().field(FIELD).regex("su[g|s]g").size(size);
|
||||
CompletionSuggestionBuilder regex = SuggestBuilders.completionSuggestion(FIELD).regex("su[g|s]g").size(size);
|
||||
assertSuggestions("foo", regex, outputs);
|
||||
|
||||
CompletionSuggestionBuilder fuzzyPrefix = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg", Fuzziness.ONE).size(size);
|
||||
CompletionSuggestionBuilder fuzzyPrefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg", Fuzziness.ONE).size(size);
|
||||
assertSuggestions("foo", fuzzyPrefix, outputs);
|
||||
}
|
||||
|
||||
|
@ -198,7 +198,7 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
}
|
||||
indexRandom(true, indexRequestBuilders);
|
||||
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg").
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg").
|
||||
size(numDocs).payload(Collections.singletonList("count"));
|
||||
SuggestResponse suggestResponse = client().prepareSuggest(INDEX).addSuggestion("foo", prefix).execute().actionGet();
|
||||
assertNoFailures(suggestResponse);
|
||||
|
@ -245,7 +245,7 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
client().prepareIndex(INDEX, TYPE, "2").setSource(FIELD, "suggestion")
|
||||
);
|
||||
indexRandom(true, indexRequestBuilders);
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg")
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg")
|
||||
.payload(Collections.singletonList("test_field"));
|
||||
SuggestResponse suggestResponse = client().prepareSuggest(INDEX).addSuggestion("foo", prefix).execute().actionGet();
|
||||
assertNoFailures(suggestResponse);
|
||||
|
@ -283,7 +283,7 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
indexRequestBuilders.add(client().prepareIndex(INDEX, TYPE, "2").setSource(source));
|
||||
indexRandom(true, indexRequestBuilders);
|
||||
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg")
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg")
|
||||
.payload(Arrays.asList("title", "count"));
|
||||
SuggestResponse suggestResponse = client().prepareSuggest(INDEX).addSuggestion("foo", prefix).execute().actionGet();
|
||||
assertNoFailures(suggestResponse);
|
||||
|
@ -334,7 +334,7 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
payloadFields.add("test_field" + i);
|
||||
}
|
||||
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg")
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg")
|
||||
.size(suggestionSize).payload(payloadFields);
|
||||
SuggestResponse suggestResponse = client().prepareSuggest(INDEX).addSuggestion("foo", prefix).execute().actionGet();
|
||||
assertNoFailures(suggestResponse);
|
||||
|
@ -435,7 +435,7 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
SuggestResponse suggestResponse = client().prepareSuggest(INDEX).addSuggestion("testSuggestions",
|
||||
new CompletionSuggestionBuilder().field(FIELD).text("test").size(10)
|
||||
new CompletionSuggestionBuilder(FIELD).text("test").size(10)
|
||||
).execute().actionGet();
|
||||
|
||||
assertSuggestions(suggestResponse, "testSuggestions", "testing");
|
||||
|
@ -636,7 +636,7 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
assertThat(putMappingResponse.isAcknowledged(), is(true));
|
||||
|
||||
SuggestResponse suggestResponse = client().prepareSuggest(INDEX).addSuggestion("suggs",
|
||||
SuggestBuilders.completionSuggestion().field(FIELD + ".suggest").text("f").size(10)
|
||||
SuggestBuilders.completionSuggestion(FIELD + ".suggest").text("f").size(10)
|
||||
).execute().actionGet();
|
||||
assertSuggestions(suggestResponse, "suggs");
|
||||
|
||||
|
@ -644,7 +644,7 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
ensureGreen(INDEX);
|
||||
|
||||
SuggestResponse afterReindexingResponse = client().prepareSuggest(INDEX).addSuggestion("suggs",
|
||||
SuggestBuilders.completionSuggestion().field(FIELD + ".suggest").text("f").size(10)
|
||||
SuggestBuilders.completionSuggestion(FIELD + ".suggest").text("f").size(10)
|
||||
).execute().actionGet();
|
||||
assertSuggestions(afterReindexingResponse, "suggs", "Foo Fighters");
|
||||
}
|
||||
|
@ -661,12 +661,12 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
SuggestResponse suggestResponse = client().prepareSuggest(INDEX).addSuggestion("foo",
|
||||
SuggestBuilders.completionSuggestion().field(FIELD).prefix("Nirv").size(10)
|
||||
SuggestBuilders.completionSuggestion(FIELD).prefix("Nirv").size(10)
|
||||
).execute().actionGet();
|
||||
assertSuggestions(suggestResponse, false, "foo", "Nirvana");
|
||||
|
||||
suggestResponse = client().prepareSuggest(INDEX).addSuggestion("foo",
|
||||
SuggestBuilders.completionSuggestion().field(FIELD).prefix("Nirw", Fuzziness.ONE).size(10)
|
||||
SuggestBuilders.completionSuggestion(FIELD).prefix("Nirw", Fuzziness.ONE).size(10)
|
||||
).execute().actionGet();
|
||||
assertSuggestions(suggestResponse, false, "foo", "Nirvana");
|
||||
}
|
||||
|
@ -684,13 +684,13 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
|
||||
// edit distance 1
|
||||
SuggestResponse suggestResponse = client().prepareSuggest(INDEX).addSuggestion("foo",
|
||||
SuggestBuilders.completionSuggestion().field(FIELD).prefix("Norw", Fuzziness.ONE).size(10)
|
||||
SuggestBuilders.completionSuggestion(FIELD).prefix("Norw", Fuzziness.ONE).size(10)
|
||||
).execute().actionGet();
|
||||
assertSuggestions(suggestResponse, false, "foo");
|
||||
|
||||
// edit distance 2
|
||||
suggestResponse = client().prepareSuggest(INDEX).addSuggestion("foo",
|
||||
SuggestBuilders.completionSuggestion().field(FIELD).prefix("Norw", Fuzziness.TWO).size(10)
|
||||
SuggestBuilders.completionSuggestion(FIELD).prefix("Norw", Fuzziness.TWO).size(10)
|
||||
).execute().actionGet();
|
||||
assertSuggestions(suggestResponse, false, "foo", "Nirvana");
|
||||
}
|
||||
|
@ -707,12 +707,12 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
SuggestResponse suggestResponse = client().prepareSuggest(INDEX).addSuggestion("foo",
|
||||
SuggestBuilders.completionSuggestion().field(FIELD).prefix("Nriv", FuzzyOptions.builder().setTranspositions(false).build()).size(10)
|
||||
SuggestBuilders.completionSuggestion(FIELD).prefix("Nriv", FuzzyOptions.builder().setTranspositions(false).build()).size(10)
|
||||
).execute().actionGet();
|
||||
assertSuggestions(suggestResponse, false, "foo");
|
||||
|
||||
suggestResponse = client().prepareSuggest(INDEX).addSuggestion("foo",
|
||||
SuggestBuilders.completionSuggestion().field(FIELD).prefix("Nriv", Fuzziness.ONE).size(10)
|
||||
SuggestBuilders.completionSuggestion(FIELD).prefix("Nriv", Fuzziness.ONE).size(10)
|
||||
).execute().actionGet();
|
||||
assertSuggestions(suggestResponse, false, "foo", "Nirvana");
|
||||
}
|
||||
|
@ -729,12 +729,12 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
SuggestResponse suggestResponse = client().prepareSuggest(INDEX).addSuggestion("foo",
|
||||
SuggestBuilders.completionSuggestion().field(FIELD).prefix("Nriva", FuzzyOptions.builder().setFuzzyMinLength(6).build()).size(10)
|
||||
SuggestBuilders.completionSuggestion(FIELD).prefix("Nriva", FuzzyOptions.builder().setFuzzyMinLength(6).build()).size(10)
|
||||
).execute().actionGet();
|
||||
assertSuggestions(suggestResponse, false, "foo");
|
||||
|
||||
suggestResponse = client().prepareSuggest(INDEX).addSuggestion("foo",
|
||||
SuggestBuilders.completionSuggestion().field(FIELD).prefix("Nrivan", FuzzyOptions.builder().setFuzzyMinLength(6).build()).size(10)
|
||||
SuggestBuilders.completionSuggestion(FIELD).prefix("Nrivan", FuzzyOptions.builder().setFuzzyMinLength(6).build()).size(10)
|
||||
).execute().actionGet();
|
||||
assertSuggestions(suggestResponse, false, "foo", "Nirvana");
|
||||
}
|
||||
|
@ -751,12 +751,12 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
SuggestResponse suggestResponse = client().prepareSuggest(INDEX).addSuggestion("foo",
|
||||
SuggestBuilders.completionSuggestion().field(FIELD).prefix("Nirw", FuzzyOptions.builder().setFuzzyPrefixLength(4).build()).size(10)
|
||||
SuggestBuilders.completionSuggestion(FIELD).prefix("Nirw", FuzzyOptions.builder().setFuzzyPrefixLength(4).build()).size(10)
|
||||
).execute().actionGet();
|
||||
assertSuggestions(suggestResponse, false, "foo");
|
||||
|
||||
suggestResponse = client().prepareSuggest(INDEX).addSuggestion("foo",
|
||||
SuggestBuilders.completionSuggestion().field(FIELD).prefix("Nirvo", FuzzyOptions.builder().setFuzzyPrefixLength(4).build()).size(10)
|
||||
SuggestBuilders.completionSuggestion(FIELD).prefix("Nirvo", FuzzyOptions.builder().setFuzzyPrefixLength(4).build()).size(10)
|
||||
).execute().actionGet();
|
||||
assertSuggestions(suggestResponse, false, "foo", "Nirvana");
|
||||
}
|
||||
|
@ -774,18 +774,18 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
|
||||
// suggestion with a character, which needs unicode awareness
|
||||
org.elasticsearch.search.suggest.completion.CompletionSuggestionBuilder completionSuggestionBuilder =
|
||||
SuggestBuilders.completionSuggestion().field(FIELD).prefix("öööи", FuzzyOptions.builder().setUnicodeAware(true).build()).size(10);
|
||||
SuggestBuilders.completionSuggestion(FIELD).prefix("öööи", FuzzyOptions.builder().setUnicodeAware(true).build()).size(10);
|
||||
|
||||
SuggestResponse suggestResponse = client().prepareSuggest(INDEX).addSuggestion("foo", completionSuggestionBuilder).execute().actionGet();
|
||||
assertSuggestions(suggestResponse, false, "foo", "ööööö");
|
||||
|
||||
// removing unicode awareness leads to no result
|
||||
completionSuggestionBuilder = SuggestBuilders.completionSuggestion().field(FIELD).prefix("öööи", FuzzyOptions.builder().setUnicodeAware(false).build()).size(10);
|
||||
completionSuggestionBuilder = SuggestBuilders.completionSuggestion(FIELD).prefix("öööи", FuzzyOptions.builder().setUnicodeAware(false).build()).size(10);
|
||||
suggestResponse = client().prepareSuggest(INDEX).addSuggestion("foo", completionSuggestionBuilder).execute().actionGet();
|
||||
assertSuggestions(suggestResponse, false, "foo");
|
||||
|
||||
// increasing edit distance instead of unicode awareness works again, as this is only a single character
|
||||
completionSuggestionBuilder = SuggestBuilders.completionSuggestion().field(FIELD).prefix("öööи", FuzzyOptions.builder().setUnicodeAware(false).setFuzziness(Fuzziness.TWO).build()).size(10);
|
||||
completionSuggestionBuilder = SuggestBuilders.completionSuggestion(FIELD).prefix("öööи", FuzzyOptions.builder().setUnicodeAware(false).setFuzziness(Fuzziness.TWO).build()).size(10);
|
||||
suggestResponse = client().prepareSuggest(INDEX).addSuggestion("foo", completionSuggestionBuilder).execute().actionGet();
|
||||
assertSuggestions(suggestResponse, false, "foo", "ööööö");
|
||||
}
|
||||
|
@ -815,8 +815,8 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
ensureGreen();
|
||||
// load the fst index into ram
|
||||
client().prepareSuggest(INDEX).addSuggestion("foo", SuggestBuilders.completionSuggestion().field(FIELD).prefix("f")).get();
|
||||
client().prepareSuggest(INDEX).addSuggestion("foo", SuggestBuilders.completionSuggestion().field(otherField).prefix("f")).get();
|
||||
client().prepareSuggest(INDEX).addSuggestion("foo", SuggestBuilders.completionSuggestion(FIELD).prefix("f")).get();
|
||||
client().prepareSuggest(INDEX).addSuggestion("foo", SuggestBuilders.completionSuggestion(otherField).prefix("f")).get();
|
||||
|
||||
// Get all stats
|
||||
IndicesStatsResponse indicesStatsResponse = client().admin().indices().prepareStats(INDEX).setIndices(INDEX).setCompletion(true).get();
|
||||
|
@ -921,14 +921,14 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
}
|
||||
public void assertSuggestions(String suggestion, String... suggestions) {
|
||||
String suggestionName = RandomStrings.randomAsciiOfLength(random(), 10);
|
||||
CompletionSuggestionBuilder suggestionBuilder = SuggestBuilders.completionSuggestion().field(FIELD).text(suggestion).size(10);
|
||||
CompletionSuggestionBuilder suggestionBuilder = SuggestBuilders.completionSuggestion(FIELD).text(suggestion).size(10);
|
||||
assertSuggestions(suggestionName, suggestionBuilder, suggestions);
|
||||
}
|
||||
|
||||
public void assertSuggestionsNotInOrder(String suggestString, String... suggestions) {
|
||||
String suggestionName = RandomStrings.randomAsciiOfLength(random(), 10);
|
||||
SuggestResponse suggestResponse = client().prepareSuggest(INDEX).addSuggestion(suggestionName,
|
||||
SuggestBuilders.completionSuggestion().field(FIELD).text(suggestString).size(10)
|
||||
SuggestBuilders.completionSuggestion(FIELD).text(suggestString).size(10)
|
||||
).execute().actionGet();
|
||||
|
||||
assertSuggestions(suggestResponse, false, suggestionName, suggestions);
|
||||
|
|
|
@ -90,7 +90,7 @@ public class ContextCompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
}
|
||||
indexRandom(true, indexRequestBuilders);
|
||||
ensureYellow(INDEX);
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg");
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg");
|
||||
assertSuggestions("foo", prefix, "suggestion9", "suggestion8", "suggestion7", "suggestion6", "suggestion5");
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ public class ContextCompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
}
|
||||
indexRandom(true, indexRequestBuilders);
|
||||
ensureYellow(INDEX);
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion().field(FIELD).regex("sugg.*es");
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).regex("sugg.*es");
|
||||
assertSuggestions("foo", prefix, "sugg9estion", "sugg8estion", "sugg7estion", "sugg6estion", "sugg5estion");
|
||||
}
|
||||
|
||||
|
@ -154,7 +154,7 @@ public class ContextCompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
}
|
||||
indexRandom(true, indexRequestBuilders);
|
||||
ensureYellow(INDEX);
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg", Fuzziness.ONE);
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg", Fuzziness.ONE);
|
||||
assertSuggestions("foo", prefix, "sugxgestion9", "sugxgestion8", "sugxgestion7", "sugxgestion6", "sugxgestion5");
|
||||
}
|
||||
|
||||
|
@ -179,7 +179,7 @@ public class ContextCompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
}
|
||||
indexRandom(true, indexRequestBuilders);
|
||||
ensureYellow(INDEX);
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg")
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg")
|
||||
.categoryContexts("cat", CategoryQueryContext.builder().setCategory("cat0").build());
|
||||
|
||||
assertSuggestions("foo", prefix, "suggestion8", "suggestion6", "suggestion4", "suggestion2", "suggestion0");
|
||||
|
@ -206,7 +206,7 @@ public class ContextCompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
}
|
||||
indexRandom(true, indexRequestBuilders);
|
||||
ensureYellow(INDEX);
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg")
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg")
|
||||
.categoryContexts("cat",
|
||||
CategoryQueryContext.builder().setCategory("cat0").setBoost(3).build(),
|
||||
CategoryQueryContext.builder().setCategory("cat1").build()
|
||||
|
@ -236,7 +236,7 @@ public class ContextCompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
}
|
||||
indexRandom(true, indexRequestBuilders);
|
||||
ensureYellow(INDEX);
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg");
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg");
|
||||
|
||||
assertSuggestions("foo", prefix, "suggestion9", "suggestion8", "suggestion7", "suggestion6", "suggestion5");
|
||||
}
|
||||
|
@ -266,17 +266,17 @@ public class ContextCompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
ensureYellow(INDEX);
|
||||
|
||||
// filter only on context cat
|
||||
CompletionSuggestionBuilder catFilterSuggest = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg");
|
||||
CompletionSuggestionBuilder catFilterSuggest = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg");
|
||||
catFilterSuggest.categoryContexts("cat", CategoryQueryContext.builder().setCategory("cat0").build());
|
||||
assertSuggestions("foo", catFilterSuggest, "suggestion8", "suggestion6", "suggestion4", "suggestion2", "suggestion0");
|
||||
|
||||
// filter only on context type
|
||||
CompletionSuggestionBuilder typeFilterSuggest = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg");
|
||||
CompletionSuggestionBuilder typeFilterSuggest = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg");
|
||||
typeFilterSuggest.categoryContexts("type", CategoryQueryContext.builder().setCategory("type2").build(),
|
||||
CategoryQueryContext.builder().setCategory("type1").build());
|
||||
assertSuggestions("foo", typeFilterSuggest, "suggestion9", "suggestion6", "suggestion5", "suggestion2", "suggestion1");
|
||||
|
||||
CompletionSuggestionBuilder multiContextFilterSuggest = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg");
|
||||
CompletionSuggestionBuilder multiContextFilterSuggest = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg");
|
||||
// query context order should never matter
|
||||
if (randomBoolean()) {
|
||||
multiContextFilterSuggest.categoryContexts("type", CategoryQueryContext.builder().setCategory("type2").build());
|
||||
|
@ -314,21 +314,21 @@ public class ContextCompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
ensureYellow(INDEX);
|
||||
|
||||
// boost only on context cat
|
||||
CompletionSuggestionBuilder catBoostSuggest = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg");
|
||||
CompletionSuggestionBuilder catBoostSuggest = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg");
|
||||
catBoostSuggest.categoryContexts("cat",
|
||||
CategoryQueryContext.builder().setCategory("cat0").setBoost(3).build(),
|
||||
CategoryQueryContext.builder().setCategory("cat1").build());
|
||||
assertSuggestions("foo", catBoostSuggest, "suggestion8", "suggestion6", "suggestion4", "suggestion9", "suggestion2");
|
||||
|
||||
// boost only on context type
|
||||
CompletionSuggestionBuilder typeBoostSuggest = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg");
|
||||
CompletionSuggestionBuilder typeBoostSuggest = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg");
|
||||
typeBoostSuggest.categoryContexts("type",
|
||||
CategoryQueryContext.builder().setCategory("type2").setBoost(2).build(),
|
||||
CategoryQueryContext.builder().setCategory("type1").setBoost(4).build());
|
||||
assertSuggestions("foo", typeBoostSuggest, "suggestion9", "suggestion5", "suggestion6", "suggestion1", "suggestion2");
|
||||
|
||||
// boost on both contexts
|
||||
CompletionSuggestionBuilder multiContextBoostSuggest = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg");
|
||||
CompletionSuggestionBuilder multiContextBoostSuggest = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg");
|
||||
// query context order should never matter
|
||||
if (randomBoolean()) {
|
||||
multiContextBoostSuggest.categoryContexts("type",
|
||||
|
@ -375,7 +375,7 @@ public class ContextCompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
}
|
||||
indexRandom(true, indexRequestBuilders);
|
||||
ensureYellow(INDEX);
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg");
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg");
|
||||
assertSuggestions("foo", prefix, "suggestion9", "suggestion8", "suggestion7", "suggestion6", "suggestion5");
|
||||
}
|
||||
|
||||
|
@ -406,7 +406,7 @@ public class ContextCompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
indexRandom(true, indexRequestBuilders);
|
||||
ensureYellow(INDEX);
|
||||
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg");
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg");
|
||||
assertSuggestions("foo", prefix, "suggestion0", "suggestion1", "suggestion2", "suggestion3", "suggestion4");
|
||||
}
|
||||
|
||||
|
@ -432,7 +432,7 @@ public class ContextCompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
}
|
||||
indexRandom(true, indexRequestBuilders);
|
||||
ensureYellow(INDEX);
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg");
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg");
|
||||
assertSuggestions("foo", prefix, "suggestion9", "suggestion8", "suggestion7", "suggestion6", "suggestion5");
|
||||
}
|
||||
|
||||
|
@ -459,10 +459,10 @@ public class ContextCompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
}
|
||||
indexRandom(true, indexRequestBuilders);
|
||||
ensureYellow(INDEX);
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg");
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg");
|
||||
assertSuggestions("foo", prefix, "suggestion9", "suggestion8", "suggestion7", "suggestion6", "suggestion5");
|
||||
|
||||
CompletionSuggestionBuilder geoFilteringPrefix = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg")
|
||||
CompletionSuggestionBuilder geoFilteringPrefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg")
|
||||
.geoContexts("geo", GeoQueryContext.builder().setGeoPoint(new GeoPoint(geoPoints[0])).build());
|
||||
|
||||
assertSuggestions("foo", geoFilteringPrefix, "suggestion8", "suggestion6", "suggestion4", "suggestion2", "suggestion0");
|
||||
|
@ -491,12 +491,12 @@ public class ContextCompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
}
|
||||
indexRandom(true, indexRequestBuilders);
|
||||
ensureYellow(INDEX);
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg");
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg");
|
||||
assertSuggestions("foo", prefix, "suggestion9", "suggestion8", "suggestion7", "suggestion6", "suggestion5");
|
||||
|
||||
GeoQueryContext context1 = GeoQueryContext.builder().setGeoPoint(geoPoints[0]).setBoost(2).build();
|
||||
GeoQueryContext context2 = GeoQueryContext.builder().setGeoPoint(geoPoints[1]).build();
|
||||
CompletionSuggestionBuilder geoBoostingPrefix = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg")
|
||||
CompletionSuggestionBuilder geoBoostingPrefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg")
|
||||
.geoContexts("geo", context1, context2);
|
||||
|
||||
assertSuggestions("foo", geoBoostingPrefix, "suggestion8", "suggestion6", "suggestion4", "suggestion9", "suggestion7");
|
||||
|
@ -527,7 +527,7 @@ public class ContextCompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
}
|
||||
indexRandom(true, indexRequestBuilders);
|
||||
ensureYellow(INDEX);
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg")
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg")
|
||||
.geoContexts("geo", GeoQueryContext.builder().setGeoPoint(new GeoPoint(52.2263, 4.543)).build());
|
||||
assertSuggestions("foo", prefix, "suggestion9", "suggestion8", "suggestion7", "suggestion6", "suggestion5");
|
||||
}
|
||||
|
@ -565,10 +565,10 @@ public class ContextCompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
}
|
||||
indexRandom(true, indexRequestBuilders);
|
||||
ensureYellow(INDEX);
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg");
|
||||
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg");
|
||||
assertSuggestions("foo", prefix, "suggestion9", "suggestion8", "suggestion7", "suggestion6", "suggestion5");
|
||||
|
||||
CompletionSuggestionBuilder geoNeighbourPrefix = SuggestBuilders.completionSuggestion().field(FIELD).prefix("sugg")
|
||||
CompletionSuggestionBuilder geoNeighbourPrefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg")
|
||||
.geoContexts("geo", GeoQueryContext.builder().setGeoPoint(GeoPoint.fromGeohash(geohash)).build());
|
||||
|
||||
assertSuggestions("foo", geoNeighbourPrefix, "suggestion9", "suggestion8", "suggestion7", "suggestion6", "suggestion5");
|
||||
|
@ -625,7 +625,7 @@ public class ContextCompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
String suggestionName = randomAsciiOfLength(10);
|
||||
CompletionSuggestionBuilder context = SuggestBuilders.completionSuggestion().field(FIELD).text("h").size(10)
|
||||
CompletionSuggestionBuilder context = SuggestBuilders.completionSuggestion(FIELD).text("h").size(10)
|
||||
.geoContexts("st", GeoQueryContext.builder().setGeoPoint(new GeoPoint(52.52, 13.4)).build());
|
||||
SuggestResponse suggestResponse = client().prepareSuggest(INDEX).addSuggestion(suggestionName, context).get();
|
||||
|
||||
|
|
|
@ -86,17 +86,15 @@ public class CustomSuggesterSearchIT extends ESIntegTestCase {
|
|||
|
||||
public final static CustomSuggestionBuilder PROTOTYPE = new CustomSuggestionBuilder("_na_", "_na_");
|
||||
|
||||
private String randomField;
|
||||
private String randomSuffix;
|
||||
|
||||
public CustomSuggestionBuilder(String randomField, String randomSuffix) {
|
||||
this.randomField = randomField;
|
||||
super(randomField);
|
||||
this.randomSuffix = randomSuffix;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected XContentBuilder innerToXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.field("field", randomField);
|
||||
builder.field("suffix", randomSuffix);
|
||||
return builder;
|
||||
}
|
||||
|
@ -108,39 +106,39 @@ public class CustomSuggesterSearchIT extends ESIntegTestCase {
|
|||
|
||||
@Override
|
||||
public void doWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeString(randomField);
|
||||
out.writeString(randomSuffix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomSuggestionBuilder doReadFrom(StreamInput in) throws IOException {
|
||||
return new CustomSuggestionBuilder(in.readString(), in.readString());
|
||||
public CustomSuggestionBuilder doReadFrom(StreamInput in, String fieldname) throws IOException {
|
||||
return new CustomSuggestionBuilder(fieldname, in.readString());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doEquals(CustomSuggestionBuilder other) {
|
||||
return Objects.equals(randomField, other.randomField) &&
|
||||
Objects.equals(randomSuffix, other.randomSuffix);
|
||||
return Objects.equals(randomSuffix, other.randomSuffix);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int doHashCode() {
|
||||
return Objects.hash(randomField, randomSuffix);
|
||||
return Objects.hash(randomSuffix);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CustomSuggestionBuilder innerFromXContent(QueryParseContext parseContext)
|
||||
throws IOException {
|
||||
// TODO some parsing
|
||||
return new CustomSuggestionBuilder(randomField, randomSuffix);
|
||||
return new CustomSuggestionBuilder(field(), randomSuffix);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SuggestionContext innerBuild(QueryShardContext context) throws IOException {
|
||||
Map<String, Object> options = new HashMap<>();
|
||||
options.put("field", randomField);
|
||||
options.put("field", field());
|
||||
options.put("suffix", randomSuffix);
|
||||
return new CustomSuggester.CustomSuggestionsContext(context, options);
|
||||
CustomSuggester.CustomSuggestionsContext customSuggestionsContext = new CustomSuggester.CustomSuggestionsContext(context, options);
|
||||
customSuggestionsContext.setField(field());
|
||||
return customSuggestionsContext;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public class CompletionSuggesterBuilderTests extends AbstractSuggestionBuilderTe
|
|||
|
||||
@Override
|
||||
protected CompletionSuggestionBuilder randomSuggestionBuilder() {
|
||||
CompletionSuggestionBuilder testBuilder = new CompletionSuggestionBuilder();
|
||||
CompletionSuggestionBuilder testBuilder = new CompletionSuggestionBuilder(randomAsciiOfLengthBetween(2, 20));
|
||||
switch (randomIntBetween(0, 3)) {
|
||||
case 0:
|
||||
testBuilder.prefix(randomAsciiOfLength(10));
|
||||
|
|
|
@ -47,7 +47,7 @@ public class PhraseSuggestionBuilderTests extends AbstractSuggestionBuilderTestC
|
|||
}
|
||||
|
||||
public static PhraseSuggestionBuilder randomPhraseSuggestionBuilder() {
|
||||
PhraseSuggestionBuilder testBuilder = new PhraseSuggestionBuilder();
|
||||
PhraseSuggestionBuilder testBuilder = new PhraseSuggestionBuilder(randomAsciiOfLengthBetween(2, 20));
|
||||
maybeSet(testBuilder::maxErrors, randomFloat());
|
||||
maybeSet(testBuilder::separator, randomAsciiOfLengthBetween(1, 10));
|
||||
maybeSet(testBuilder::realWordErrorLikelihood, randomFloat());
|
||||
|
@ -193,4 +193,83 @@ public class PhraseSuggestionBuilderTests extends AbstractSuggestionBuilderTestC
|
|||
}
|
||||
}
|
||||
|
||||
public void testInvalidParameters() throws IOException {
|
||||
// test missing field name
|
||||
try {
|
||||
new PhraseSuggestionBuilder(null);
|
||||
fail("Should not allow null as field name");
|
||||
} catch (NullPointerException e) {
|
||||
assertEquals("suggestion requires a field name", e.getMessage());
|
||||
}
|
||||
|
||||
// test emtpy field name
|
||||
try {
|
||||
new PhraseSuggestionBuilder("");
|
||||
fail("Should not allow empty string as field name");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("suggestion field name is empty", e.getMessage());
|
||||
}
|
||||
|
||||
PhraseSuggestionBuilder builder = new PhraseSuggestionBuilder(randomAsciiOfLengthBetween(2, 20));
|
||||
try {
|
||||
builder.gramSize(0);
|
||||
fail("Should not allow gramSize < 1");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("gramSize must be >= 1", e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
builder.gramSize(-1);
|
||||
fail("Should not allow gramSize < 1");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("gramSize must be >= 1", e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
builder.maxErrors(-1);
|
||||
fail("Should not allow maxErrors < 0");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("max_error must be > 0.0", e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
builder.separator(null);
|
||||
fail("Should not allow null as separator");
|
||||
} catch (NullPointerException e) {
|
||||
assertEquals("separator cannot be set to null", e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
builder.realWordErrorLikelihood(-1);
|
||||
fail("Should not allow real world error likelihood < 0");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("real_word_error_likelihood must be > 0.0", e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
builder.confidence(-1);
|
||||
fail("Should not allow confidence < 0");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("confidence must be >= 0.0", e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
builder.tokenLimit(0);
|
||||
fail("token_limit must be >= 1");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("token_limit must be >= 1", e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
if (randomBoolean()) {
|
||||
builder.highlight(null, "</b>");
|
||||
} else {
|
||||
builder.highlight("<b>", null);
|
||||
}
|
||||
fail("Pre and post tag must both be null or both not be null.");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("Pre and post tag must both be null or both not be null.", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,7 +28,13 @@ import org.elasticsearch.search.suggest.term.TermSuggestionBuilder.SuggestMode;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.elasticsearch.search.suggest.DirectSpellcheckerSettings.DEFAULT_ACCURACY;
|
||||
import static org.elasticsearch.search.suggest.DirectSpellcheckerSettings.DEFAULT_MAX_EDITS;
|
||||
import static org.elasticsearch.search.suggest.DirectSpellcheckerSettings.DEFAULT_MAX_INSPECTIONS;
|
||||
import static org.elasticsearch.search.suggest.DirectSpellcheckerSettings.DEFAULT_MAX_TERM_FREQ;
|
||||
import static org.elasticsearch.search.suggest.DirectSpellcheckerSettings.DEFAULT_MIN_DOC_FREQ;
|
||||
import static org.elasticsearch.search.suggest.DirectSpellcheckerSettings.DEFAULT_MIN_WORD_LENGTH;
|
||||
import static org.elasticsearch.search.suggest.DirectSpellcheckerSettings.DEFAULT_PREFIX_LENGTH;
|
||||
|
||||
/**
|
||||
* Test the {@link TermSuggestionBuilder} class.
|
||||
|
@ -40,7 +46,7 @@ public class TermSuggestionBuilderTests extends AbstractSuggestionBuilderTestCas
|
|||
*/
|
||||
@Override
|
||||
protected TermSuggestionBuilder randomSuggestionBuilder() {
|
||||
TermSuggestionBuilder testBuilder = new TermSuggestionBuilder();
|
||||
TermSuggestionBuilder testBuilder = new TermSuggestionBuilder(randomAsciiOfLengthBetween(2, 20));
|
||||
maybeSet(testBuilder::suggestMode, randomSuggestMode());
|
||||
maybeSet(testBuilder::accuracy, randomFloat());
|
||||
maybeSet(testBuilder::sort, randomSort());
|
||||
|
@ -124,7 +130,23 @@ public class TermSuggestionBuilderTests extends AbstractSuggestionBuilderTestCas
|
|||
}
|
||||
|
||||
public void testInvalidParameters() throws IOException {
|
||||
TermSuggestionBuilder builder = new TermSuggestionBuilder();
|
||||
// test missing field name
|
||||
try {
|
||||
new TermSuggestionBuilder(null);
|
||||
fail("Should not allow null as field name");
|
||||
} catch (NullPointerException e) {
|
||||
assertEquals("suggestion requires a field name", e.getMessage());
|
||||
}
|
||||
|
||||
// test emtpy field name
|
||||
try {
|
||||
new TermSuggestionBuilder("");
|
||||
fail("Should not allow empty string as field name");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("suggestion field name is empty", e.getMessage());
|
||||
}
|
||||
|
||||
TermSuggestionBuilder builder = new TermSuggestionBuilder(randomAsciiOfLengthBetween(2, 20));
|
||||
// test invalid accuracy values
|
||||
try {
|
||||
builder.accuracy(-0.5f);
|
||||
|
@ -237,17 +259,17 @@ public class TermSuggestionBuilderTests extends AbstractSuggestionBuilderTestCas
|
|||
}
|
||||
|
||||
public void testDefaultValuesSet() {
|
||||
TermSuggestionBuilder builder = new TermSuggestionBuilder();
|
||||
assertThat(builder.accuracy(), notNullValue());
|
||||
assertThat(builder.maxEdits(), notNullValue());
|
||||
assertThat(builder.maxInspections(), notNullValue());
|
||||
assertThat(builder.maxTermFreq(), notNullValue());
|
||||
assertThat(builder.minDocFreq(), notNullValue());
|
||||
assertThat(builder.minWordLength(), notNullValue());
|
||||
assertThat(builder.prefixLength(), notNullValue());
|
||||
assertThat(builder.sort(), notNullValue());
|
||||
assertThat(builder.stringDistance(), notNullValue());
|
||||
assertThat(builder.suggestMode(), notNullValue());
|
||||
TermSuggestionBuilder builder = new TermSuggestionBuilder(randomAsciiOfLengthBetween(2, 20));
|
||||
assertEquals(DEFAULT_ACCURACY, builder.accuracy(), Float.MIN_VALUE);
|
||||
assertEquals(DEFAULT_MAX_EDITS, builder.maxEdits());
|
||||
assertEquals(DEFAULT_MAX_INSPECTIONS, builder.maxInspections());
|
||||
assertEquals(DEFAULT_MAX_TERM_FREQ, builder.maxTermFreq(), Float.MIN_VALUE);
|
||||
assertEquals(DEFAULT_MIN_DOC_FREQ, builder.minDocFreq(), Float.MIN_VALUE);
|
||||
assertEquals(DEFAULT_MIN_WORD_LENGTH, builder.minWordLength());
|
||||
assertEquals(DEFAULT_PREFIX_LENGTH, builder.prefixLength());
|
||||
assertEquals(SortBy.SCORE, builder.sort());
|
||||
assertEquals(StringDistanceImpl.INTERNAL, builder.stringDistance());
|
||||
assertEquals(SuggestMode.MISSING, builder.suggestMode());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -671,6 +671,13 @@ The inner DirectCandidateGenerator class has been moved out to its own class cal
|
|||
|
||||
The `setText` method has been changed to `setGlobalText` to make the intent more clear, and a `getGlobalText` method has been added.
|
||||
|
||||
The `addSuggestion` method now required the user specified suggestion name, previously used in the ctor of each
|
||||
suggestion.
|
||||
|
||||
=== SuggestionBuilder
|
||||
|
||||
The `field` setter has been deleted. Instead the field name needs to be specified as constructor argument.
|
||||
|
||||
==== Elasticsearch will no longer detect logging implementations
|
||||
|
||||
Elasticsearch now logs only to log4j 1.2. Previously if log4j wasn't on the classpath it made some effort to degrade to
|
||||
|
|
|
@ -20,38 +20,6 @@
|
|||
package org.elasticsearch.messy.tests;
|
||||
|
||||
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
|
||||
import static org.elasticsearch.search.suggest.SuggestBuilders.phraseSuggestion;
|
||||
import static org.elasticsearch.search.suggest.SuggestBuilders.termSuggestion;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSuggestion;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSuggestionPhraseCollateMatchExists;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSuggestionSize;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
|
||||
import static org.hamcrest.Matchers.anyOf;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
|
@ -81,6 +49,38 @@ import org.elasticsearch.search.suggest.term.TermSuggestionBuilder.SuggestMode;
|
|||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
|
||||
import static org.elasticsearch.search.suggest.SuggestBuilders.phraseSuggestion;
|
||||
import static org.elasticsearch.search.suggest.SuggestBuilders.termSuggestion;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSuggestion;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSuggestionPhraseCollateMatchExists;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSuggestionSize;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
|
||||
import static org.hamcrest.Matchers.anyOf;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
/**
|
||||
* Integration tests for term and phrase suggestions. Many of these tests many requests that vary only slightly from one another. Where
|
||||
* possible these tests should declare for the first request, make the request, modify the configuration for the next request, make that
|
||||
|
@ -104,10 +104,9 @@ public class SuggestSearchTests extends ESIntegTestCase {
|
|||
index("test", "type1", "4", "text", "abcc");
|
||||
refresh();
|
||||
|
||||
TermSuggestionBuilder termSuggest = termSuggestion()
|
||||
TermSuggestionBuilder termSuggest = termSuggestion("text")
|
||||
.suggestMode(TermSuggestionBuilder.SuggestMode.ALWAYS) // Always, otherwise the results can vary between requests.
|
||||
.text("abcd")
|
||||
.field("text");
|
||||
.text("abcd");
|
||||
logger.info("--> run suggestions with one index");
|
||||
searchSuggest("test", termSuggest);
|
||||
createIndex("test_1");
|
||||
|
@ -118,11 +117,10 @@ public class SuggestSearchTests extends ESIntegTestCase {
|
|||
index("test_1", "type1", "3", "text", "ab bd");
|
||||
index("test_1", "type1", "4", "text", "ab cc");
|
||||
refresh();
|
||||
termSuggest = termSuggestion()
|
||||
termSuggest = termSuggestion("text")
|
||||
.suggestMode(SuggestMode.ALWAYS) // Always, otherwise the results can vary between requests.
|
||||
.text("ab cd")
|
||||
.minWordLength(1)
|
||||
.field("text");
|
||||
.minWordLength(1);
|
||||
logger.info("--> run suggestions with two indices");
|
||||
searchSuggest("test", termSuggest);
|
||||
|
||||
|
@ -145,11 +143,10 @@ public class SuggestSearchTests extends ESIntegTestCase {
|
|||
index("test_2", "type1", "4", "text", "abcc");
|
||||
refresh();
|
||||
|
||||
termSuggest = termSuggestion()
|
||||
termSuggest = termSuggestion("text")
|
||||
.suggestMode(SuggestMode.ALWAYS) // Always, otherwise the results can vary between requests.
|
||||
.text("ab cd")
|
||||
.minWordLength(1)
|
||||
.field("text");
|
||||
.minWordLength(1);
|
||||
logger.info("--> run suggestions with three indices");
|
||||
try {
|
||||
searchSuggest("test", termSuggest);
|
||||
|
@ -165,11 +162,10 @@ public class SuggestSearchTests extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
|
||||
termSuggest = termSuggestion()
|
||||
termSuggest = termSuggestion("text")
|
||||
.suggestMode(SuggestMode.ALWAYS) // Always, otherwise the results can vary between requests.
|
||||
.text("ABCD")
|
||||
.minWordLength(1)
|
||||
.field("text");
|
||||
.minWordLength(1);
|
||||
logger.info("--> run suggestions with four indices");
|
||||
try {
|
||||
searchSuggest("test", termSuggest);
|
||||
|
@ -219,7 +215,7 @@ public class SuggestSearchTests extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
DirectCandidateGeneratorBuilder generator = candidateGenerator("name").prefixLength(0).minWordLength(0).suggestMode("always").maxEdits(2);
|
||||
PhraseSuggestionBuilder phraseSuggestion = phraseSuggestion().field("name.shingled")
|
||||
PhraseSuggestionBuilder phraseSuggestion = phraseSuggestion("name.shingled")
|
||||
.addCandidateGenerator(generator)
|
||||
.gramSize(3);
|
||||
Suggest searchSuggest = searchSuggest("ice tea", "did_you_mean", phraseSuggestion);
|
||||
|
@ -255,10 +251,9 @@ public class SuggestSearchTests extends ESIntegTestCase {
|
|||
SearchResponse search = client().prepareSearch().setQuery(matchQuery("text", "spellchecker")).get();
|
||||
assertThat("didn't ask for suggestions but got some", search.getSuggest(), nullValue());
|
||||
|
||||
TermSuggestionBuilder termSuggestion = termSuggestion()
|
||||
TermSuggestionBuilder termSuggestion = termSuggestion("text")
|
||||
.suggestMode(SuggestMode.ALWAYS) // Always, otherwise the results can vary between requests.
|
||||
.text("abcd")
|
||||
.field("text")
|
||||
.size(10);
|
||||
Suggest suggest = searchSuggest("test", termSuggestion);
|
||||
assertSuggestion(suggest, 0, "test", 10, "abc0");
|
||||
|
@ -298,13 +293,15 @@ public class SuggestSearchTests extends ESIntegTestCase {
|
|||
client().prepareIndex("test", "type1").setSource("name", "I like ice cream."));
|
||||
refresh();
|
||||
|
||||
PhraseSuggestionBuilder phraseSuggestion = phraseSuggestion().field("name.shingled")
|
||||
PhraseSuggestionBuilder phraseSuggestion = phraseSuggestion("name.shingled")
|
||||
.addCandidateGenerator(candidateGenerator("name").prefixLength(0).minWordLength(0).suggestMode("always").maxEdits(2))
|
||||
.gramSize(3);
|
||||
Suggest searchSuggest = searchSuggest("ice tea", "did_you_mean", phraseSuggestion);
|
||||
assertSuggestion(searchSuggest, 0, 0, "did_you_mean", "iced tea");
|
||||
|
||||
phraseSuggestion.field("nosuchField");
|
||||
phraseSuggestion = phraseSuggestion("nosuchField")
|
||||
.addCandidateGenerator(candidateGenerator("name").prefixLength(0).minWordLength(0).suggestMode("always").maxEdits(2))
|
||||
.gramSize(3);
|
||||
{
|
||||
SearchRequestBuilder searchBuilder = client().prepareSearch().setSize(0);
|
||||
searchBuilder.suggest(new SuggestBuilder().setGlobalText("tetsting sugestion").addSuggestion("did_you_mean", phraseSuggestion));
|
||||
|
@ -330,10 +327,9 @@ public class SuggestSearchTests extends ESIntegTestCase {
|
|||
SearchResponse search = client().prepareSearch().setQuery(matchQuery("text", "spellcecker")).get();
|
||||
assertThat("didn't ask for suggestions but got some", search.getSuggest(), nullValue());
|
||||
|
||||
TermSuggestionBuilder termSuggest = termSuggestion()
|
||||
TermSuggestionBuilder termSuggest = termSuggestion("text")
|
||||
.suggestMode(SuggestMode.ALWAYS) // Always, otherwise the results can vary between requests.
|
||||
.text("abcd")
|
||||
.field("text");
|
||||
.text("abcd");
|
||||
Suggest suggest = searchSuggest("test", termSuggest);
|
||||
assertSuggestion(suggest, 0, "test", "aacd", "abbd", "abcc");
|
||||
assertThat(suggest.getSuggestion("test").getEntries().get(0).getText().string(), equalTo("abcd"));
|
||||
|
@ -350,10 +346,9 @@ public class SuggestSearchTests extends ESIntegTestCase {
|
|||
index("test", "type1", "1", "foo", "bar");
|
||||
refresh();
|
||||
|
||||
TermSuggestionBuilder termSuggest = termSuggestion()
|
||||
TermSuggestionBuilder termSuggest = termSuggestion("text")
|
||||
.suggestMode(SuggestMode.ALWAYS) // Always, otherwise the results can vary between requests.
|
||||
.text("abcd")
|
||||
.field("text");
|
||||
.text("abcd");
|
||||
Suggest suggest = searchSuggest("test", termSuggest);
|
||||
assertSuggestionSize(suggest, 0, 0, "test");
|
||||
assertThat(suggest.getSuggestion("test").getEntries().get(0).getText().string(), equalTo("abcd"));
|
||||
|
@ -374,14 +369,14 @@ public class SuggestSearchTests extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
Map<String, SuggestionBuilder<?>> suggestions = new HashMap<>();
|
||||
suggestions.put("size1", termSuggestion()
|
||||
suggestions.put("size1", termSuggestion("field1")
|
||||
.size(1).text("prefix_abcd").maxTermFreq(10).prefixLength(1).minDocFreq(0)
|
||||
.field("field1").suggestMode(SuggestMode.ALWAYS));
|
||||
suggestions.put("field2", termSuggestion()
|
||||
.field("field2").text("prefix_eeeh prefix_efgh")
|
||||
.suggestMode(SuggestMode.ALWAYS));
|
||||
suggestions.put("field2", termSuggestion("field2")
|
||||
.text("prefix_eeeh prefix_efgh")
|
||||
.maxTermFreq(10).minDocFreq(0).suggestMode(SuggestMode.ALWAYS));
|
||||
suggestions.put("accuracy", termSuggestion()
|
||||
.field("field2").text("prefix_efgh").accuracy(1f)
|
||||
suggestions.put("accuracy", termSuggestion("field2")
|
||||
.text("prefix_efgh").accuracy(1f)
|
||||
.maxTermFreq(10).minDocFreq(0).suggestMode(SuggestMode.ALWAYS));
|
||||
Suggest suggest = searchSuggest(null, 0, suggestions);
|
||||
assertSuggestion(suggest, 0, "size1", "prefix_aacd");
|
||||
|
@ -418,16 +413,16 @@ public class SuggestSearchTests extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
Map<String, SuggestionBuilder<?>> suggestions = new HashMap<>();
|
||||
suggestions.put("size3SortScoreFirst", termSuggestion()
|
||||
.size(3).minDocFreq(0).field("field1").suggestMode(SuggestMode.ALWAYS));
|
||||
suggestions.put("size10SortScoreFirst", termSuggestion()
|
||||
.size(10).minDocFreq(0).field("field1").suggestMode(SuggestMode.ALWAYS).shardSize(50));
|
||||
suggestions.put("size3SortScoreFirstMaxEdits1", termSuggestion()
|
||||
suggestions.put("size3SortScoreFirst", termSuggestion("field1")
|
||||
.size(3).minDocFreq(0).suggestMode(SuggestMode.ALWAYS));
|
||||
suggestions.put("size10SortScoreFirst", termSuggestion("field1")
|
||||
.size(10).minDocFreq(0).suggestMode(SuggestMode.ALWAYS).shardSize(50));
|
||||
suggestions.put("size3SortScoreFirstMaxEdits1", termSuggestion("field1")
|
||||
.maxEdits(1)
|
||||
.size(10).minDocFreq(0).field("field1").suggestMode(SuggestMode.ALWAYS));
|
||||
suggestions.put("size10SortFrequencyFirst", termSuggestion()
|
||||
.size(10).minDocFreq(0).suggestMode(SuggestMode.ALWAYS));
|
||||
suggestions.put("size10SortFrequencyFirst", termSuggestion("field1")
|
||||
.size(10).sort(SortBy.FREQUENCY).shardSize(1000)
|
||||
.minDocFreq(0).field("field1").suggestMode(SuggestMode.ALWAYS));
|
||||
.minDocFreq(0).suggestMode(SuggestMode.ALWAYS));
|
||||
Suggest suggest = searchSuggest("prefix_abcd", 0, suggestions);
|
||||
|
||||
// The commented out assertions fail sometimes because suggestions are based off of shard frequencies instead of index frequencies.
|
||||
|
@ -453,7 +448,7 @@ public class SuggestSearchTests extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
Suggest searchSuggest = searchSuggest( "a an the", "simple_phrase",
|
||||
phraseSuggestion().field("body").gramSize(1)
|
||||
phraseSuggestion("body").gramSize(1)
|
||||
.addCandidateGenerator(candidateGenerator("body").minWordLength(1).suggestMode("always"))
|
||||
.size(1));
|
||||
assertSuggestionSize(searchSuggest, 0, 0, "simple_phrase");
|
||||
|
@ -489,13 +484,13 @@ public class SuggestSearchTests extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
Suggest searchSuggest = searchSuggest( "hello word", "simple_phrase",
|
||||
phraseSuggestion().field("body")
|
||||
phraseSuggestion("body")
|
||||
.addCandidateGenerator(candidateGenerator("body").prefixLength(4).minWordLength(1).suggestMode("always"))
|
||||
.size(1).confidence(1.0f));
|
||||
assertSuggestion(searchSuggest, 0, "simple_phrase", "hello words");
|
||||
|
||||
searchSuggest = searchSuggest( "hello word", "simple_phrase",
|
||||
phraseSuggestion().field("body")
|
||||
phraseSuggestion("body")
|
||||
.addCandidateGenerator(candidateGenerator("body").prefixLength(2).minWordLength(1).suggestMode("always"))
|
||||
.size(1).confidence(1.0f));
|
||||
assertSuggestion(searchSuggest, 0, "simple_phrase", "hello world");
|
||||
|
@ -543,8 +538,7 @@ public class SuggestSearchTests extends ESIntegTestCase {
|
|||
}
|
||||
refresh();
|
||||
|
||||
PhraseSuggestionBuilder phraseSuggest = phraseSuggestion()
|
||||
.field("bigram").gramSize(2).analyzer("body")
|
||||
PhraseSuggestionBuilder phraseSuggest = phraseSuggestion("bigram").gramSize(2).analyzer("body")
|
||||
.addCandidateGenerator(candidateGenerator("body").minWordLength(1).suggestMode("always"))
|
||||
.size(1);
|
||||
Suggest searchSuggest = searchSuggest( "american ame", "simple_phrase", phraseSuggest);
|
||||
|
@ -680,9 +674,8 @@ public class SuggestSearchTests extends ESIntegTestCase {
|
|||
index("test", "type1", "2", "body", line, "body_reverse", line, "bigram", line);
|
||||
refresh();
|
||||
|
||||
PhraseSuggestionBuilder phraseSuggestion = phraseSuggestion()
|
||||
PhraseSuggestionBuilder phraseSuggestion = phraseSuggestion("bigram")
|
||||
.realWordErrorLikelihood(0.95f)
|
||||
.field("bigram")
|
||||
.gramSize(2)
|
||||
.analyzer("body")
|
||||
.addCandidateGenerator(candidateGenerator("body").minWordLength(1).prefixLength(1).suggestMode("always").size(1).accuracy(0.1f))
|
||||
|
@ -740,8 +733,7 @@ public class SuggestSearchTests extends ESIntegTestCase {
|
|||
NumShards numShards = getNumShards("test");
|
||||
|
||||
// Lets make sure some things throw exceptions
|
||||
PhraseSuggestionBuilder phraseSuggestion = phraseSuggestion()
|
||||
.field("bigram")
|
||||
PhraseSuggestionBuilder phraseSuggestion = phraseSuggestion("bigram")
|
||||
.analyzer("body")
|
||||
.addCandidateGenerator(candidateGenerator("does_not_exist").minWordLength(1).suggestMode("always"))
|
||||
.realWordErrorLikelihood(0.95f)
|
||||
|
@ -773,10 +765,15 @@ public class SuggestSearchTests extends ESIntegTestCase {
|
|||
searchSuggest( "Xor the Got-Jewel", 0, suggestion);
|
||||
|
||||
// Field doesn't produce unigrams but the analyzer does
|
||||
phraseSuggestion.forceUnigrams(true).field("bigram").analyzer("ngram");
|
||||
phraseSuggestion.forceUnigrams(true).analyzer("ngram");
|
||||
searchSuggest( "Xor the Got-Jewel", 0, suggestion);
|
||||
|
||||
phraseSuggestion.field("ngram").analyzer("myDefAnalyzer")
|
||||
phraseSuggestion = phraseSuggestion("ngram")
|
||||
.analyzer("myDefAnalyzer")
|
||||
.forceUnigrams(true)
|
||||
.realWordErrorLikelihood(0.95f)
|
||||
.maxErrors(0.5f)
|
||||
.size(1)
|
||||
.addCandidateGenerator(candidateGenerator("body").minWordLength(1).suggestMode("always"));
|
||||
Suggest suggest = searchSuggest( "Xor the Got-Jewel", 0, suggestion);
|
||||
|
||||
|
@ -801,8 +798,8 @@ public class SuggestSearchTests extends ESIntegTestCase {
|
|||
client().prepareIndex("test", "type1", "3").setSource("field1", "foobar3").setRouting("3"));
|
||||
|
||||
Suggest suggest = searchSuggest( "foobar", "simple",
|
||||
termSuggestion()
|
||||
.size(10).minDocFreq(0).field("field1").suggestMode(SuggestMode.ALWAYS));
|
||||
termSuggestion("field1")
|
||||
.size(10).minDocFreq(0).suggestMode(SuggestMode.ALWAYS));
|
||||
ElasticsearchAssertions.assertSuggestionSize(suggest, 0, 3, "simple");
|
||||
}
|
||||
|
||||
|
@ -842,14 +839,14 @@ public class SuggestSearchTests extends ESIntegTestCase {
|
|||
SearchRequestBuilder request = client().prepareSearch().setSize(0)
|
||||
.suggest(
|
||||
new SuggestBuilder().setGlobalText("tetsting sugestion").addSuggestion("did_you_mean",
|
||||
phraseSuggestion().field("fielddoesnotexist").maxErrors(5.0f)));
|
||||
phraseSuggestion("fielddoesnotexist").maxErrors(5.0f)));
|
||||
assertThrows(request, SearchPhaseExecutionException.class);
|
||||
|
||||
// When searching on a shard which does not hold yet any document of an existing type, we should not fail
|
||||
SearchResponse searchResponse = client().prepareSearch().setSize(0)
|
||||
.suggest(
|
||||
new SuggestBuilder().setGlobalText("tetsting sugestion").addSuggestion("did_you_mean",
|
||||
phraseSuggestion().field("name").maxErrors(5.0f)))
|
||||
phraseSuggestion("name").maxErrors(5.0f)))
|
||||
.get();
|
||||
ElasticsearchAssertions.assertNoFailures(searchResponse);
|
||||
ElasticsearchAssertions.assertSuggestion(searchResponse.getSuggest(), 0, 0, "did_you_mean", "testing suggestions");
|
||||
|
@ -888,7 +885,7 @@ public class SuggestSearchTests extends ESIntegTestCase {
|
|||
.setSize(0)
|
||||
.suggest(
|
||||
new SuggestBuilder().setGlobalText("tetsting sugestion").addSuggestion("did_you_mean",
|
||||
phraseSuggestion().field("name").maxErrors(5.0f)))
|
||||
phraseSuggestion("name").maxErrors(5.0f)))
|
||||
.get();
|
||||
|
||||
assertNoFailures(searchResponse);
|
||||
|
@ -945,16 +942,14 @@ public class SuggestSearchTests extends ESIntegTestCase {
|
|||
}
|
||||
refresh();
|
||||
|
||||
Suggest searchSuggest = searchSuggest("nobel prize", "simple_phrase", phraseSuggestion()
|
||||
.field("body")
|
||||
Suggest searchSuggest = searchSuggest("nobel prize", "simple_phrase", phraseSuggestion("body")
|
||||
.addCandidateGenerator(candidateGenerator("body").minWordLength(1).suggestMode("always").maxTermFreq(.99f))
|
||||
.confidence(2f)
|
||||
.maxErrors(5f)
|
||||
.size(1));
|
||||
assertSuggestionSize(searchSuggest, 0, 0, "simple_phrase");
|
||||
|
||||
searchSuggest = searchSuggest("noble prize", "simple_phrase", phraseSuggestion()
|
||||
.field("body")
|
||||
searchSuggest = searchSuggest("noble prize", "simple_phrase", phraseSuggestion("body")
|
||||
.addCandidateGenerator(candidateGenerator("body").minWordLength(1).suggestMode("always").maxTermFreq(.99f))
|
||||
.confidence(2f)
|
||||
.maxErrors(5f)
|
||||
|
@ -1084,8 +1079,7 @@ public class SuggestSearchTests extends ESIntegTestCase {
|
|||
}
|
||||
indexRandom(true, builders);
|
||||
|
||||
PhraseSuggestionBuilder suggest = phraseSuggestion()
|
||||
.field("title")
|
||||
PhraseSuggestionBuilder suggest = phraseSuggestion("title")
|
||||
.addCandidateGenerator(candidateGenerator("title")
|
||||
.suggestMode("always")
|
||||
.maxTermFreq(.99f)
|
||||
|
@ -1149,8 +1143,7 @@ public class SuggestSearchTests extends ESIntegTestCase {
|
|||
indexRandom(true, builders);
|
||||
|
||||
// suggest without collate
|
||||
PhraseSuggestionBuilder suggest = phraseSuggestion()
|
||||
.field("title")
|
||||
PhraseSuggestionBuilder suggest = phraseSuggestion("title")
|
||||
.addCandidateGenerator(candidateGenerator("title")
|
||||
.suggestMode("always")
|
||||
.maxTermFreq(.99f)
|
||||
|
|
Loading…
Reference in New Issue