Search in sources :

Example 1 with CompletionAnalyzer

use of org.apache.lucene.search.suggest.document.CompletionAnalyzer in project elasticsearch by elastic.

the class CompletionFieldMapperTests method testCompletionAnalyzerSettings.

public void testCompletionAnalyzerSettings() throws Exception {
    String mapping = jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("completion").field("type", "completion").field("analyzer", "simple").field("search_analyzer", "standard").field("preserve_separators", false).field("preserve_position_increments", true).endObject().endObject().endObject().endObject().string();
    DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
    FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion");
    assertThat(fieldMapper, instanceOf(CompletionFieldMapper.class));
    MappedFieldType completionFieldType = fieldMapper.fieldType();
    NamedAnalyzer indexAnalyzer = completionFieldType.indexAnalyzer();
    assertThat(indexAnalyzer.name(), equalTo("simple"));
    assertThat(indexAnalyzer.analyzer(), instanceOf(CompletionAnalyzer.class));
    CompletionAnalyzer analyzer = (CompletionAnalyzer) indexAnalyzer.analyzer();
    assertThat(analyzer.preservePositionIncrements(), equalTo(true));
    assertThat(analyzer.preserveSep(), equalTo(false));
    NamedAnalyzer searchAnalyzer = completionFieldType.searchAnalyzer();
    assertThat(searchAnalyzer.name(), equalTo("standard"));
    assertThat(searchAnalyzer.analyzer(), instanceOf(CompletionAnalyzer.class));
    analyzer = (CompletionAnalyzer) searchAnalyzer.analyzer();
    assertThat(analyzer.preservePositionIncrements(), equalTo(true));
    assertThat(analyzer.preserveSep(), equalTo(false));
}
Also used : NamedAnalyzer(org.elasticsearch.index.analysis.NamedAnalyzer) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) CompletionAnalyzer(org.apache.lucene.search.suggest.document.CompletionAnalyzer) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 2 with CompletionAnalyzer

use of org.apache.lucene.search.suggest.document.CompletionAnalyzer in project elasticsearch by elastic.

the class CompletionFieldMapperTests method testDefaultConfiguration.

public void testDefaultConfiguration() throws IOException {
    String mapping = jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("completion").field("type", "completion").endObject().endObject().endObject().endObject().string();
    DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
    FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion");
    assertThat(fieldMapper, instanceOf(CompletionFieldMapper.class));
    MappedFieldType completionFieldType = fieldMapper.fieldType();
    NamedAnalyzer indexAnalyzer = completionFieldType.indexAnalyzer();
    assertThat(indexAnalyzer.name(), equalTo("simple"));
    assertThat(indexAnalyzer.analyzer(), instanceOf(CompletionAnalyzer.class));
    CompletionAnalyzer analyzer = (CompletionAnalyzer) indexAnalyzer.analyzer();
    assertThat(analyzer.preservePositionIncrements(), equalTo(true));
    assertThat(analyzer.preserveSep(), equalTo(true));
    NamedAnalyzer searchAnalyzer = completionFieldType.searchAnalyzer();
    assertThat(searchAnalyzer.name(), equalTo("simple"));
    assertThat(searchAnalyzer.analyzer(), instanceOf(CompletionAnalyzer.class));
    analyzer = (CompletionAnalyzer) searchAnalyzer.analyzer();
    assertThat(analyzer.preservePositionIncrements(), equalTo(true));
    assertThat(analyzer.preserveSep(), equalTo(true));
}
Also used : NamedAnalyzer(org.elasticsearch.index.analysis.NamedAnalyzer) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) CompletionAnalyzer(org.apache.lucene.search.suggest.document.CompletionAnalyzer) Matchers.containsString(org.hamcrest.Matchers.containsString)

Aggregations

CompletionAnalyzer (org.apache.lucene.search.suggest.document.CompletionAnalyzer)2 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)2 NamedAnalyzer (org.elasticsearch.index.analysis.NamedAnalyzer)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2