Search in sources :

Example 16 with AnalyzeResponse

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

the class TransportAnalyzeActionTests method testNonPreBuildTokenFilter.

public void testNonPreBuildTokenFilter() throws IOException {
    AnalyzeRequest request = new AnalyzeRequest();
    request.tokenizer("whitespace");
    request.addTokenFilter("min_hash");
    request.text("the quick brown fox");
    AnalyzeResponse analyze = TransportAnalyzeAction.analyze(request, AllFieldMapper.NAME, null, indexAnalyzers, registry, environment);
    List<AnalyzeResponse.AnalyzeToken> tokens = analyze.getTokens();
    int default_hash_count = 1;
    int default_bucket_size = 512;
    int default_hash_set_size = 1;
    assertEquals(default_hash_count * default_bucket_size * default_hash_set_size, tokens.size());
}
Also used : AnalyzeRequest(org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest) AnalyzeResponse(org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse)

Example 17 with AnalyzeResponse

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

the class TransportAnalyzeActionTests method testFillsAttributes.

public void testFillsAttributes() throws IOException {
    AnalyzeRequest request = new AnalyzeRequest();
    request.analyzer("standard");
    request.text("the 1 brown fox");
    AnalyzeResponse analyze = TransportAnalyzeAction.analyze(request, AllFieldMapper.NAME, null, null, registry, environment);
    List<AnalyzeResponse.AnalyzeToken> tokens = analyze.getTokens();
    assertEquals(4, tokens.size());
    assertEquals("the", tokens.get(0).getTerm());
    assertEquals(0, tokens.get(0).getStartOffset());
    assertEquals(3, tokens.get(0).getEndOffset());
    assertEquals(0, tokens.get(0).getPosition());
    assertEquals("<ALPHANUM>", tokens.get(0).getType());
    assertEquals("1", tokens.get(1).getTerm());
    assertEquals(4, tokens.get(1).getStartOffset());
    assertEquals(5, tokens.get(1).getEndOffset());
    assertEquals(1, tokens.get(1).getPosition());
    assertEquals("<NUM>", tokens.get(1).getType());
    assertEquals("brown", tokens.get(2).getTerm());
    assertEquals(6, tokens.get(2).getStartOffset());
    assertEquals(11, tokens.get(2).getEndOffset());
    assertEquals(2, tokens.get(2).getPosition());
    assertEquals("<ALPHANUM>", tokens.get(2).getType());
    assertEquals("fox", tokens.get(3).getTerm());
    assertEquals(12, tokens.get(3).getStartOffset());
    assertEquals(15, tokens.get(3).getEndOffset());
    assertEquals(3, tokens.get(3).getPosition());
    assertEquals("<ALPHANUM>", tokens.get(3).getType());
}
Also used : AnalyzeRequest(org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest) AnalyzeResponse(org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse)

Example 18 with AnalyzeResponse

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

the class AnalyzeActionIT method testDetailAnalyzeWithNoIndex.

public void testDetailAnalyzeWithNoIndex() throws Exception {
    //analyzer only
    AnalyzeResponse analyzeResponse = client().admin().indices().prepareAnalyze("THIS IS A TEST").setExplain(true).setAnalyzer("simple").get();
    assertThat(analyzeResponse.detail().tokenizer(), IsNull.nullValue());
    assertThat(analyzeResponse.detail().tokenfilters(), IsNull.nullValue());
    assertThat(analyzeResponse.detail().charfilters(), IsNull.nullValue());
    assertThat(analyzeResponse.detail().analyzer().getName(), equalTo("simple"));
    assertThat(analyzeResponse.detail().analyzer().getTokens().length, equalTo(4));
}
Also used : AnalyzeResponse(org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse)

Example 19 with AnalyzeResponse

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

the class AnalyzeActionIT method testSimpleAnalyzerTests.

public void testSimpleAnalyzerTests() throws Exception {
    assertAcked(prepareCreate("test").addAlias(new Alias("alias")));
    ensureGreen();
    for (int i = 0; i < 10; i++) {
        AnalyzeResponse analyzeResponse = client().admin().indices().prepareAnalyze(indexOrAlias(), "this is a test").get();
        assertThat(analyzeResponse.getTokens().size(), equalTo(4));
        AnalyzeResponse.AnalyzeToken token = analyzeResponse.getTokens().get(0);
        assertThat(token.getTerm(), equalTo("this"));
        assertThat(token.getStartOffset(), equalTo(0));
        assertThat(token.getEndOffset(), equalTo(4));
        assertThat(token.getPosition(), equalTo(0));
        assertThat(token.getPositionLength(), equalTo(1));
        token = analyzeResponse.getTokens().get(1);
        assertThat(token.getTerm(), equalTo("is"));
        assertThat(token.getStartOffset(), equalTo(5));
        assertThat(token.getEndOffset(), equalTo(7));
        assertThat(token.getPosition(), equalTo(1));
        assertThat(token.getPositionLength(), equalTo(1));
        token = analyzeResponse.getTokens().get(2);
        assertThat(token.getTerm(), equalTo("a"));
        assertThat(token.getStartOffset(), equalTo(8));
        assertThat(token.getEndOffset(), equalTo(9));
        assertThat(token.getPosition(), equalTo(2));
        assertThat(token.getPositionLength(), equalTo(1));
        token = analyzeResponse.getTokens().get(3);
        assertThat(token.getTerm(), equalTo("test"));
        assertThat(token.getStartOffset(), equalTo(10));
        assertThat(token.getEndOffset(), equalTo(14));
        assertThat(token.getPosition(), equalTo(3));
        assertThat(token.getPositionLength(), equalTo(1));
    }
}
Also used : Alias(org.elasticsearch.action.admin.indices.alias.Alias) AnalyzeResponse(org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse)

Example 20 with AnalyzeResponse

use of org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse 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

AnalyzeResponse (org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse)25 Alias (org.elasticsearch.action.admin.indices.alias.Alias)10 AnalyzeRequest (org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest)4 HashMap (java.util.HashMap)3 AnalyzeRequestBuilder (org.elasticsearch.action.admin.indices.analyze.AnalyzeRequestBuilder)2 AnalyzeToken (org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse.AnalyzeToken)2 SearchException (core.framework.search.SearchException)1 StopWatch (core.framework.util.StopWatch)1 ArrayList (java.util.ArrayList)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1