Search in sources :

Example 1 with AnalyzeRequestBuilder

use of org.elasticsearch.action.admin.indices.analyze.AnalyzeRequestBuilder in project elasticsearch by elastic.

the class AnalyzeActionIT method testAnalyzerWithMultiValues.

public void testAnalyzerWithMultiValues() throws Exception {
    assertAcked(prepareCreate("test").addAlias(new Alias("alias")));
    ensureGreen();
    client().admin().indices().preparePutMapping("test").setType("document").setSource("simple", "type=text,analyzer=simple,position_increment_gap=100").get();
    String[] texts = new String[] { "THIS IS A TEST", "THE SECOND TEXT" };
    final AnalyzeRequestBuilder requestBuilder = client().admin().indices().prepareAnalyze();
    requestBuilder.setText(texts);
    requestBuilder.setIndex(indexOrAlias());
    requestBuilder.setField("simple");
    AnalyzeResponse analyzeResponse = requestBuilder.get();
    assertThat(analyzeResponse.getTokens().size(), equalTo(7));
    AnalyzeResponse.AnalyzeToken token = analyzeResponse.getTokens().get(3);
    assertThat(token.getTerm(), equalTo("test"));
    assertThat(token.getPosition(), equalTo(3));
    assertThat(token.getStartOffset(), equalTo(10));
    assertThat(token.getEndOffset(), equalTo(14));
    assertThat(token.getPositionLength(), equalTo(1));
    token = analyzeResponse.getTokens().get(5);
    assertThat(token.getTerm(), equalTo("second"));
    assertThat(token.getPosition(), equalTo(105));
    assertThat(token.getStartOffset(), equalTo(19));
    assertThat(token.getEndOffset(), equalTo(25));
    assertThat(token.getPositionLength(), equalTo(1));
}
Also used : Alias(org.elasticsearch.action.admin.indices.alias.Alias) AnalyzeRequestBuilder(org.elasticsearch.action.admin.indices.analyze.AnalyzeRequestBuilder) AnalyzeResponse(org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse)

Example 2 with AnalyzeRequestBuilder

use of org.elasticsearch.action.admin.indices.analyze.AnalyzeRequestBuilder in project elasticsearch by elastic.

the class AnalyzeActionIT method testAnalyzerWithFieldOrTypeTests.

public void testAnalyzerWithFieldOrTypeTests() throws Exception {
    assertAcked(prepareCreate("test").addAlias(new Alias("alias")));
    ensureGreen();
    client().admin().indices().preparePutMapping("test").setType("document").setSource("simple", "type=text,analyzer=simple").get();
    for (int i = 0; i < 10; i++) {
        final AnalyzeRequestBuilder requestBuilder = client().admin().indices().prepareAnalyze("THIS IS A TEST");
        requestBuilder.setIndex(indexOrAlias());
        requestBuilder.setField("document.simple");
        AnalyzeResponse analyzeResponse = requestBuilder.get();
        assertThat(analyzeResponse.getTokens().size(), equalTo(4));
        AnalyzeResponse.AnalyzeToken token = analyzeResponse.getTokens().get(3);
        assertThat(token.getTerm(), equalTo("test"));
        assertThat(token.getStartOffset(), equalTo(10));
        assertThat(token.getEndOffset(), equalTo(14));
        assertThat(token.getPositionLength(), equalTo(1));
    }
}
Also used : Alias(org.elasticsearch.action.admin.indices.alias.Alias) AnalyzeRequestBuilder(org.elasticsearch.action.admin.indices.analyze.AnalyzeRequestBuilder) AnalyzeResponse(org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse)

Aggregations

Alias (org.elasticsearch.action.admin.indices.alias.Alias)2 AnalyzeRequestBuilder (org.elasticsearch.action.admin.indices.analyze.AnalyzeRequestBuilder)2 AnalyzeResponse (org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse)2