|
@@ -29,6 +29,8 @@ import org.junit.Test;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
+import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
|
|
+import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
|
|
|
/**
|
|
@@ -106,6 +108,49 @@ public class AnalyzeActionTests extends ElasticsearchIntegrationTest {
|
|
|
analyzeResponse = client().admin().indices().prepareAnalyze("THIS IS A TEST").setTokenizer("keyword").setTokenFilters("lowercase").execute().actionGet();
|
|
|
assertThat(analyzeResponse.getTokens().size(), equalTo(1));
|
|
|
assertThat(analyzeResponse.getTokens().get(0).getTerm(), equalTo("this is a test"));
|
|
|
+
|
|
|
+ analyzeResponse = client().admin().indices().prepareAnalyze("THIS IS A TEST").setTokenizer("standard").setTokenFilters("lowercase", "reverse").execute().actionGet();
|
|
|
+ assertThat(analyzeResponse.getTokens().size(), equalTo(4));
|
|
|
+ AnalyzeResponse.AnalyzeToken token = analyzeResponse.getTokens().get(0);
|
|
|
+ assertThat(token.getTerm(), equalTo("siht"));
|
|
|
+ token = analyzeResponse.getTokens().get(1);
|
|
|
+ assertThat(token.getTerm(), equalTo("si"));
|
|
|
+ token = analyzeResponse.getTokens().get(2);
|
|
|
+ assertThat(token.getTerm(), equalTo("a"));
|
|
|
+ token = analyzeResponse.getTokens().get(3);
|
|
|
+ assertThat(token.getTerm(), equalTo("tset"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void analyzeWithCharFilters() throws Exception {
|
|
|
+
|
|
|
+ assertAcked(prepareCreate("test").setSettings(settingsBuilder()
|
|
|
+ .put(indexSettings())
|
|
|
+ .put("index.analysis.char_filter.custom_mapping.type", "mapping")
|
|
|
+ .putArray("index.analysis.char_filter.custom_mapping.mappings", "ph=>f", "qu=>q")
|
|
|
+ .put("index.analysis.analyzer.custom_with_char_filter.tokenizer", "standard")
|
|
|
+ .putArray("index.analysis.analyzer.custom_with_char_filter.char_filter", "custom_mapping")));
|
|
|
+ ensureGreen();
|
|
|
+
|
|
|
+ AnalyzeResponse analyzeResponse = client().admin().indices().prepareAnalyze("<h2><b>THIS</b> IS A</h2> <a href=\"#\">TEST</a>").setTokenizer("standard").setCharFilters("html_strip").execute().actionGet();
|
|
|
+ assertThat(analyzeResponse.getTokens().size(), equalTo(4));
|
|
|
+
|
|
|
+ analyzeResponse = client().admin().indices().prepareAnalyze("THIS IS A <b>TEST</b>").setTokenizer("keyword").setTokenFilters("lowercase").setCharFilters("html_strip").execute().actionGet();
|
|
|
+ assertThat(analyzeResponse.getTokens().size(), equalTo(1));
|
|
|
+ assertThat(analyzeResponse.getTokens().get(0).getTerm(), equalTo("this is a test"));
|
|
|
+
|
|
|
+ analyzeResponse = client().admin().indices().prepareAnalyze("test", "jeff quit phish").setTokenizer("keyword").setTokenFilters("lowercase").setCharFilters("custom_mapping").execute().actionGet();
|
|
|
+ assertThat(analyzeResponse.getTokens().size(), equalTo(1));
|
|
|
+ assertThat(analyzeResponse.getTokens().get(0).getTerm(), equalTo("jeff qit fish"));
|
|
|
+
|
|
|
+ analyzeResponse = client().admin().indices().prepareAnalyze("test", "<a href=\"#\">jeff quit fish</a>").setTokenizer("standard").setCharFilters("html_strip", "custom_mapping").execute().actionGet();
|
|
|
+ assertThat(analyzeResponse.getTokens().size(), equalTo(3));
|
|
|
+ AnalyzeResponse.AnalyzeToken token = analyzeResponse.getTokens().get(0);
|
|
|
+ assertThat(token.getTerm(), equalTo("jeff"));
|
|
|
+ token = analyzeResponse.getTokens().get(1);
|
|
|
+ assertThat(token.getTerm(), equalTo("qit"));
|
|
|
+ token = analyzeResponse.getTokens().get(2);
|
|
|
+ assertThat(token.getTerm(), equalTo("fish"));
|
|
|
}
|
|
|
|
|
|
@Test
|