use of org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest 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());
}
use of org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest in project elasticsearch by elastic.
the class RestAnalyzeActionTests method testParseXContentForAnalyzeRequestWithCustomFilters.
public void testParseXContentForAnalyzeRequestWithCustomFilters() throws Exception {
XContentParser content = createParser(XContentFactory.jsonBuilder().startObject().field("text", "THIS IS A TEST").field("tokenizer", "keyword").startArray("filter").value("lowercase").startObject().field("type", "stop").array("stopwords", "foo", "buzz").endObject().endArray().startArray("char_filter").startObject().field("type", "mapping").array("mappings", "ph => f", "qu => q").endObject().endArray().endObject());
AnalyzeRequest analyzeRequest = new AnalyzeRequest("for test");
RestAnalyzeAction.buildFromContent(content, analyzeRequest);
assertThat(analyzeRequest.text().length, equalTo(1));
assertThat(analyzeRequest.text(), equalTo(new String[] { "THIS IS A TEST" }));
assertThat(analyzeRequest.tokenizer().name, equalTo("keyword"));
assertThat(analyzeRequest.tokenFilters().size(), equalTo(2));
assertThat(analyzeRequest.tokenFilters().get(0).name, equalTo("lowercase"));
assertThat(analyzeRequest.tokenFilters().get(1).definition, notNullValue());
assertThat(analyzeRequest.charFilters().size(), equalTo(1));
assertThat(analyzeRequest.charFilters().get(0).definition, notNullValue());
}
use of org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest in project elasticsearch by elastic.
the class RestAnalyzeActionTests method testParseXContentForAnalyzeRequestWithUnknownParamThrowsException.
public void testParseXContentForAnalyzeRequestWithUnknownParamThrowsException() throws Exception {
AnalyzeRequest analyzeRequest = new AnalyzeRequest("for test");
XContentParser invalidContent = createParser(XContentFactory.jsonBuilder().startObject().field("text", "THIS IS A TEST").field("unknown", "keyword").endObject());
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> RestAnalyzeAction.buildFromContent(invalidContent, analyzeRequest));
assertThat(e.getMessage(), startsWith("Unknown parameter [unknown]"));
}
use of org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest in project elasticsearch by elastic.
the class RestAnalyzeActionTests method testParseXContentForAnalyzeRequestWithInvalidStringExplainParamThrowsException.
public void testParseXContentForAnalyzeRequestWithInvalidStringExplainParamThrowsException() throws Exception {
AnalyzeRequest analyzeRequest = new AnalyzeRequest("for test");
XContentParser invalidExplain = createParser(XContentFactory.jsonBuilder().startObject().field("explain", "fals").endObject());
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> RestAnalyzeAction.buildFromContent(invalidExplain, analyzeRequest));
assertThat(e.getMessage(), startsWith("explain must be either 'true' or 'false'"));
}
use of org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest in project elasticsearch by elastic.
the class IndicesRequestIT method testAnalyze.
public void testAnalyze() {
String analyzeShardAction = AnalyzeAction.NAME + "[s]";
interceptTransportActions(analyzeShardAction);
AnalyzeRequest analyzeRequest = new AnalyzeRequest(randomIndexOrAlias());
analyzeRequest.text("text");
internalCluster().coordOnlyNodeClient().admin().indices().analyze(analyzeRequest).actionGet();
clearInterceptedActions();
assertSameIndices(analyzeRequest, analyzeShardAction);
}
Aggregations