@ClusterScope(scope = Scope.SUITE, transportClientRatio = 0.0)
public class SuggestBuildersTest extends AbstractSuggestTest {
@Override
public List<String> getSuggestions(SuggestionQuery suggestionQuery) throws Exception {
SuggestRequestBuilder builder = new SuggestRequestBuilder(client())
.setIndices(suggestionQuery.index)
.field(suggestionQuery.field)
.term(suggestionQuery.term);
if (suggestionQuery.size != null) {
builder.size(suggestionQuery.size);
}
if (suggestionQuery.similarity != null && suggestionQuery.similarity > 0.0 && suggestionQuery.similarity < 1.0) {
builder.similarity(suggestionQuery.similarity);
}
if (suggestionQuery.suggestType != null) {
builder.suggestType(suggestionQuery.suggestType);
}
if (Strings.hasLength(suggestionQuery.indexAnalyzer)) {
builder.indexAnalyzer(suggestionQuery.indexAnalyzer);
}
if (Strings.hasLength(suggestionQuery.queryAnalyzer)) {
builder.queryAnalyzer(suggestionQuery.queryAnalyzer);
}
if (Strings.hasLength(suggestionQuery.analyzer)) {
builder.analyzer(suggestionQuery.analyzer);
}
builder.preservePositionIncrements(suggestionQuery.preservePositionIncrements);
SuggestResponse suggestResponse = builder.execute().actionGet();
assertThat(suggestResponse.getShardFailures(), is(emptyArray()));
return suggestResponse.suggestions();
}