use of org.elasticsearch.search.suggest.completion.context.CategoryContextMapping in project elasticsearch by elastic.
the class ContextCompletionSuggestSearchIT method testContextFilteringWorksWithUTF8Categories.
public void testContextFilteringWorksWithUTF8Categories() throws Exception {
CategoryContextMapping contextMapping = ContextBuilder.category("cat").field("cat").build();
LinkedHashMap<String, ContextMapping> map = new LinkedHashMap<>(Collections.singletonMap("cat", contextMapping));
final CompletionMappingBuilder mapping = new CompletionMappingBuilder().context(map);
createIndexAndMapping(mapping);
IndexResponse indexResponse = client().prepareIndex(INDEX, TYPE, "1").setSource(jsonBuilder().startObject().startObject(FIELD).field("input", "suggestion").endObject().field("cat", "ctx\\u00e4").endObject()).get();
assertThat(indexResponse.status(), equalTo(RestStatus.CREATED));
assertNoFailures(client().admin().indices().prepareRefresh(INDEX).get());
CompletionSuggestionBuilder contextSuggestQuery = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg").contexts(Collections.singletonMap("cat", Collections.singletonList(CategoryQueryContext.builder().setCategory("ctx\\u00e4").build())));
assertSuggestions("foo", contextSuggestQuery, "suggestion");
}
use of org.elasticsearch.search.suggest.completion.context.CategoryContextMapping in project elasticsearch by elastic.
the class CategoryContextMappingTests method testQueryContextParsingArray.
public void testQueryContextParsingArray() throws Exception {
XContentBuilder builder = jsonBuilder().startArray().value("context1").value("context2").endArray();
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
CategoryContextMapping mapping = ContextBuilder.category("cat").build();
List<ContextMapping.InternalQueryContext> internalQueryContexts = mapping.parseQueryContext(createParseContext(parser));
assertThat(internalQueryContexts.size(), equalTo(2));
assertThat(internalQueryContexts.get(0).context, equalTo("context1"));
assertThat(internalQueryContexts.get(0).boost, equalTo(1));
assertThat(internalQueryContexts.get(0).isPrefix, equalTo(false));
assertThat(internalQueryContexts.get(1).context, equalTo("context2"));
assertThat(internalQueryContexts.get(1).boost, equalTo(1));
assertThat(internalQueryContexts.get(1).isPrefix, equalTo(false));
}
Aggregations