Search in sources :

Example 11 with CategoryContextMapping

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");
}
Also used : CompletionSuggestionBuilder(org.elasticsearch.search.suggest.completion.CompletionSuggestionBuilder) GeoContextMapping(org.elasticsearch.search.suggest.completion.context.GeoContextMapping) ContextMapping(org.elasticsearch.search.suggest.completion.context.ContextMapping) CategoryContextMapping(org.elasticsearch.search.suggest.completion.context.CategoryContextMapping) IndexResponse(org.elasticsearch.action.index.IndexResponse) CompletionMappingBuilder(org.elasticsearch.search.suggest.CompletionSuggestSearchIT.CompletionMappingBuilder) CategoryContextMapping(org.elasticsearch.search.suggest.completion.context.CategoryContextMapping) LinkedHashMap(java.util.LinkedHashMap)

Example 12 with CategoryContextMapping

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));
}
Also used : XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) XContentParser(org.elasticsearch.common.xcontent.XContentParser) CategoryContextMapping(org.elasticsearch.search.suggest.completion.context.CategoryContextMapping)

Aggregations

CategoryContextMapping (org.elasticsearch.search.suggest.completion.context.CategoryContextMapping)12 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)8 LinkedHashMap (java.util.LinkedHashMap)6 ContextMapping (org.elasticsearch.search.suggest.completion.context.ContextMapping)6 GeoContextMapping (org.elasticsearch.search.suggest.completion.context.GeoContextMapping)6 XContentParser (org.elasticsearch.common.xcontent.XContentParser)5 CompletionMappingBuilder (org.elasticsearch.search.suggest.CompletionSuggestSearchIT.CompletionMappingBuilder)4 CompletionSuggestionBuilder (org.elasticsearch.search.suggest.completion.CompletionSuggestionBuilder)4 ArrayList (java.util.ArrayList)3 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)3 GeoPoint (org.elasticsearch.common.geo.GeoPoint)3 Map (java.util.Map)2 HashMap (java.util.HashMap)1 StringField (org.apache.lucene.document.StringField)1 IndexResponse (org.elasticsearch.action.index.IndexResponse)1 ParseContext (org.elasticsearch.index.mapper.ParseContext)1 ParsedDocument (org.elasticsearch.index.mapper.ParsedDocument)1 QueryParseContext (org.elasticsearch.index.query.QueryParseContext)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1