use of org.elasticsearch.xcontent.ToXContent in project spring-data-elasticsearch by spring-projects.
the class CompletionWithContextsIntegrationTests method shouldFindSuggestionsForGivenCriteriaQueryUsingContextCompletionEntityOfKotlin.
// DATAES-536
@Test
public void shouldFindSuggestionsForGivenCriteriaQueryUsingContextCompletionEntityOfKotlin() {
// given
loadContextCompletionObjectEntities();
SuggestionBuilder completionSuggestionFuzzyBuilder = SuggestBuilders.completionSuggestion("suggest").prefix("m", Fuzziness.AUTO);
Map<String, List<? extends ToXContent>> contextMap = new HashMap<>();
List<CategoryQueryContext> contexts = new ArrayList<>(1);
CategoryQueryContext.Builder builder = CategoryQueryContext.builder();
builder.setCategory("kotlin");
CategoryQueryContext queryContext = builder.build();
contexts.add(queryContext);
contextMap.put(ContextCompletionEntity.LANGUAGE_CATEGORY, contexts);
((CompletionSuggestionBuilder) completionSuggestionFuzzyBuilder).contexts(contextMap);
// when
SearchResponse suggestResponse = ((AbstractElasticsearchTemplate) operations).suggest(new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder), IndexCoordinates.of("test-index-context-completion"));
assertThat(suggestResponse.getSuggest()).isNotNull();
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
// then
assertThat(options).hasSize(2);
assertThat(options.get(0).getText().string()).isIn("Marchand", "Mohsin");
assertThat(options.get(1).getText().string()).isIn("Marchand", "Mohsin");
}
use of org.elasticsearch.xcontent.ToXContent in project spring-data-elasticsearch by spring-projects.
the class CompletionWithContextsIntegrationTests method shouldFindSuggestionsForGivenCriteriaQueryUsingContextCompletionEntityOfElastic.
// DATAES-536
@Test
public void shouldFindSuggestionsForGivenCriteriaQueryUsingContextCompletionEntityOfElastic() {
// given
loadContextCompletionObjectEntities();
SuggestionBuilder completionSuggestionFuzzyBuilder = SuggestBuilders.completionSuggestion("suggest").prefix("m", Fuzziness.AUTO);
Map<String, List<? extends ToXContent>> contextMap = new HashMap<>();
List<CategoryQueryContext> contexts = new ArrayList<>(1);
CategoryQueryContext.Builder builder = CategoryQueryContext.builder();
builder.setCategory("elastic");
CategoryQueryContext queryContext = builder.build();
contexts.add(queryContext);
contextMap.put(ContextCompletionEntity.LANGUAGE_CATEGORY, contexts);
((CompletionSuggestionBuilder) completionSuggestionFuzzyBuilder).contexts(contextMap);
// when
SearchResponse suggestResponse = ((AbstractElasticsearchTemplate) operations).suggest(new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder), IndexCoordinates.of("test-index-context-completion"));
assertThat(suggestResponse.getSuggest()).isNotNull();
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
// then
assertThat(options).hasSize(1);
assertThat(options.get(0).getText().string()).isEqualTo("Mohsin");
}
use of org.elasticsearch.xcontent.ToXContent in project spring-data-elasticsearch by spring-projects.
the class CompletionWithContextsIntegrationTests method shouldFindSuggestionsForGivenCriteriaQueryUsingContextCompletionEntityOfMongo.
// DATAES-536
@Test
public void shouldFindSuggestionsForGivenCriteriaQueryUsingContextCompletionEntityOfMongo() {
// given
loadContextCompletionObjectEntities();
SuggestionBuilder completionSuggestionFuzzyBuilder = SuggestBuilders.completionSuggestion("suggest").prefix("m", Fuzziness.AUTO);
Map<String, List<? extends ToXContent>> contextMap = new HashMap<>();
List<CategoryQueryContext> contexts = new ArrayList<>(1);
CategoryQueryContext.Builder builder = CategoryQueryContext.builder();
builder.setCategory("mongo");
CategoryQueryContext queryContext = builder.build();
contexts.add(queryContext);
contextMap.put(ContextCompletionEntity.LANGUAGE_CATEGORY, contexts);
((CompletionSuggestionBuilder) completionSuggestionFuzzyBuilder).contexts(contextMap);
// when
SearchResponse suggestResponse = ((AbstractElasticsearchTemplate) operations).suggest(new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder), IndexCoordinates.of("test-index-context-completion"));
assertThat(suggestResponse.getSuggest()).isNotNull();
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
// then
assertThat(options).hasSize(1);
assertThat(options.get(0).getText().string()).isEqualTo("Marchand");
}
Aggregations