Examples of AnalyzeResponse


Examples of org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse

  }
 
  public List<String> analyze(String string, String index) throws IndexMissingException {
    List<String> tokens = Lists.newArrayList();
    AnalyzeRequestBuilder arb = new AnalyzeRequestBuilder(c.admin().indices(), index, string);
    AnalyzeResponse r = c.admin().indices().analyze(arb.request()).actionGet();
   
    for (AnalyzeToken token : r.getTokens()) {
      tokens.add(token.getTerm());
    }
   
    return tokens;
  }
View Full Code Here

Examples of org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse

        client.admin().indices().prepareCreate("test").execute().actionGet();
        client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();

        for (int i = 0; i < 10; i++) {
            AnalyzeResponse analyzeResponse = client.admin().indices().prepareAnalyze("test", "this is a test").execute().actionGet();
            assertThat(analyzeResponse.tokens().size(), equalTo(1));
            AnalyzeResponse.AnalyzeToken token = analyzeResponse.tokens().get(0);
            assertThat(token.term(), equalTo("test"));
            assertThat(token.startOffset(), equalTo(10));
            assertThat(token.endOffset(), equalTo(14));
        }
    }
View Full Code Here

Examples of org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse

        ).execute().actionGet();

        for (int i = 0; i < 10; i++) {
            final AnalyzeRequestBuilder requestBuilder = client.admin().indices().prepareAnalyze("test", "THIS IS A TEST");
            requestBuilder.setField("document.simple");
            AnalyzeResponse analyzeResponse = requestBuilder.execute().actionGet();
            assertThat(analyzeResponse.tokens().size(), equalTo(4));
            AnalyzeResponse.AnalyzeToken token = analyzeResponse.tokens().get(3);
            assertThat(token.term(), equalTo("test"));
            assertThat(token.startOffset(), equalTo(10));
            assertThat(token.endOffset(), equalTo(14));
        }
    }
View Full Code Here

Examples of org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse

    public static final String ANALYZER = "configured_analyzer";

    protected void assertAnalyzesTo(String analyzer, String input, String[] output, int startOffsets[], int endOffsets[], String types[], int posIncrements[]) {
        assertThat(output, notNullValue());
        AnalyzeResponse response = client().admin().indices().analyze(new AnalyzeRequest(INDEX, input).analyzer(analyzer)).actionGet();
        if (VERBOSE) {
            try {
                Map<String,String> params = new HashMap<String,String>();
                params.put("format", "text");
                logger.info("Tokens for \""+input+"\": " + response.toXContent(jsonBuilder().startObject(), new ToXContent.MapParams(params)).endObject().string());
            } catch (IOException e) {
                logger.error("Tokens for \""+input+"\": ERROR", e);
            }
        }
        Iterator<AnalyzeResponse.AnalyzeToken> tokens = response.iterator();
        int pos = 0;
        for (int i = 0; i < output.length; i++) {
            assertTrue("token "+i+" does not exist", tokens.hasNext());
            AnalyzeResponse.AnalyzeToken token = tokens.next();
            assertThat("term "+i, token.getTerm(), equalTo(output[i]));
View Full Code Here

Examples of org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse

                .build();
    }

    @Test
    public void testSmartcnAnalyzer() throws ExecutionException, InterruptedException {
        AnalyzeResponse response = client().admin().indices()
                .prepareAnalyze("叻出色").setAnalyzer("smartcn")
                .execute().get();

        assertThat(response, notNullValue());
        assertThat(response.getTokens().size(), is(2));
    }
View Full Code Here

Examples of org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse

        assertThat(response.getTokens().size(), is(2));
    }

    @Test
    public void testSmartcnTokenizer() throws ExecutionException, InterruptedException {
        AnalyzeResponse response = client().admin().indices()
                .prepareAnalyze("叻出色").setTokenizer("smartcn_tokenizer")
                .execute().get();

        assertThat(response, notNullValue());
        assertThat(response.getTokens().size(), is(2));
    }
View Full Code Here

Examples of org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse

    @Test
    public void testPhoneticAnalyzer() throws ExecutionException, InterruptedException {
        createIndex("test");
        ensureGreen("test");
        AnalyzeResponse response = client().admin().indices()
                .prepareAnalyze("hello world")
                .setIndex("test")
                .setAnalyzer("my_analyzer")
                .execute().get();

        assertThat(response, notNullValue());
        assertThat(response.getTokens().size(), is(4));
        assertThat(response.getTokens().get(0).getTerm(), is("HL"));
        assertThat(response.getTokens().get(1).getTerm(), is("hello"));
        assertThat(response.getTokens().get(2).getTerm(), is("WRLT"));
        assertThat(response.getTokens().get(3).getTerm(), is("world"));
    }
View Full Code Here

Examples of org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse

    @Test
    public void testAnalyze() {
        createIndexWithAlias();
        assertAcked(client().admin().indices().preparePutMapping("test").setType("test").setSource("field", "type=string,analyzer=keyword"));
        ensureYellow("test");
        AnalyzeResponse analyzeResponse = client().admin().indices().prepareAnalyze("this is a test").setIndex(indexOrAlias()).setField("field").get();
        assertThat(analyzeResponse.getTokens().size(), equalTo(1));
        assertThat(analyzeResponse.getTokens().get(0).getTerm(), equalTo("this is a test"));
    }
View Full Code Here

Examples of org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse

                // TODO: only skip strings containing complex chars when comparing against ES <= 1.3.x
                input = TestUtil.randomAnalysisString(getRandom(), 100, false);
                matcher = complexUnicodeChars.matcher(input);
            } while (matcher.find());

            AnalyzeResponse test = client().admin().indices().prepareAnalyze("test", input).setField("field_" + i).get();
            inout[i] = new InputOutput(test, input, "field_" + i);
        }

        logClusterState();
        boolean upgraded;
        do {
            logClusterState();
            upgraded = backwardsCluster().upgradeOneNode();
            ensureYellow();
        } while (upgraded);

        for (int i = 0; i < inout.length; i++) {
            InputOutput inputOutput = inout[i];
            AnalyzeResponse test = client().admin().indices().prepareAnalyze("test", inputOutput.input).setField(inputOutput.field).get();
            List<AnalyzeResponse.AnalyzeToken> tokens = test.getTokens();
            List<AnalyzeResponse.AnalyzeToken>  expectedTokens = inputOutput.response.getTokens();
            assertThat("size mismatch field: " + fields[i*2] + " analyzer: " + fields[i*2 + 1] + " input: " + BaseTokenStreamTestCase.escape(inputOutput.input), expectedTokens.size(), equalTo(tokens.size()));
            for (int j = 0; j < tokens.size(); j++) {
                String msg = "failed for term: " + expectedTokens.get(j).getTerm() + " field: " + fields[i*2] + " analyzer: " + fields[i*2 + 1] + " input: " + BaseTokenStreamTestCase.escape(inputOutput.input);
                assertThat(msg,  BaseTokenStreamTestCase.escape(expectedTokens.get(j).getTerm()), equalTo(BaseTokenStreamTestCase.escape(tokens.get(j).getTerm())));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.