Search in sources :

Example 26 with Settings

use of org.elasticsearch.common.settings.Settings in project crate by crate.

the class FulltextAnalyzerResolverTest method resolveAnalyzerExtendingCustom.

@Test
public void resolveAnalyzerExtendingCustom() throws Exception {
    execute("CREATE ANALYZER a5 (" + "   tokenizer whitespace," + "   token_filters (" + "       lowercase," + "       germanstemmer WITH (" + "           type='stemmer'," + "           language='german'" + "       )" + "   )" + ")");
    Settings fullAnalyzerSettings = fulltextAnalyzerResolver.resolveFullCustomAnalyzerSettings("a5");
    assertThat(fullAnalyzerSettings.getAsMap(), hasEntry("index.analysis.analyzer.a5.type", "custom"));
    assertThat(fullAnalyzerSettings.getAsMap(), hasEntry("index.analysis.analyzer.a5.tokenizer", "whitespace"));
    assertThat(fullAnalyzerSettings.getAsArray("index.analysis.analyzer.a5.filter"), arrayContainingInAnyOrder("lowercase", "a5_germanstemmer"));
    assertThat(fullAnalyzerSettings.getAsMap(), allOf(hasEntry("index.analysis.filter.a5_germanstemmer.type", "stemmer"), hasEntry("index.analysis.filter.a5_germanstemmer.language", "german")));
    execute("CREATE ANALYZER a5e EXTENDS a5 (" + "   tokenizer letter," + "   char_filters (" + "       \"html_strip\"," + "       mymapping WITH (" + "           type='mapping'," + "           mappings=['ph=>f', 'ß=>ss', 'ö=>oe']" + "       )" + "   )" + ")");
    fullAnalyzerSettings = fulltextAnalyzerResolver.resolveFullCustomAnalyzerSettings("a5e");
    assertThat(fullAnalyzerSettings.getAsMap(), hasEntry("index.analysis.analyzer.a5e.type", "custom"));
    assertThat(fullAnalyzerSettings.getAsMap(), hasEntry("index.analysis.analyzer.a5e.tokenizer", "letter"));
    assertThat(fullAnalyzerSettings.getAsArray("index.analysis.analyzer.a5e.filter"), arrayContainingInAnyOrder("lowercase", "a5_germanstemmer"));
    assertThat(fullAnalyzerSettings.getAsMap(), allOf(hasEntry("index.analysis.filter.a5_germanstemmer.type", "stemmer"), hasEntry("index.analysis.filter.a5_germanstemmer.language", "german")));
    assertThat(fullAnalyzerSettings.getAsArray("index.analysis.analyzer.a5e.char_filter"), arrayContainingInAnyOrder("html_strip", "a5e_mymapping"));
}
Also used : Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Example 27 with Settings

use of org.elasticsearch.common.settings.Settings in project crate by crate.

the class FulltextAnalyzerResolverTest method resolveAnalyzerExtendingBuiltin.

@Test
public void resolveAnalyzerExtendingBuiltin() throws Exception {
    execute("CREATE ANALYZER a4 EXTENDS " + "german WITH (" + "   \"stop_words\"=['der', 'die', 'das']" + ")");
    Settings fullAnalyzerSettings = fulltextAnalyzerResolver.resolveFullCustomAnalyzerSettings("a4");
    assertThat(fullAnalyzerSettings.getAsMap(), hasEntry("index.analysis.analyzer.a4.type", "german"));
    assertThat(fullAnalyzerSettings.getAsArray("index.analysis.analyzer.a4.stop_words"), arrayContainingInAnyOrder("der", "die", "das"));
    // extend analyzer who extends builtin analyzer (chain can be longer than 1)
    execute("CREATE ANALYZER a4e EXTENDS " + "a4 WITH (" + "   \"stop_words\"=['der', 'die', 'das', 'wer', 'wie', 'was']" + ")");
    fullAnalyzerSettings = fulltextAnalyzerResolver.resolveFullCustomAnalyzerSettings("a4e");
    assertThat(fullAnalyzerSettings.getAsMap(), hasEntry("index.analysis.analyzer.a4e.type", "german"));
    assertThat(fullAnalyzerSettings.getAsArray("index.analysis.analyzer.a4e.stop_words"), arrayContainingInAnyOrder("der", "die", "das", "wer", "wie", "was"));
}
Also used : Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Example 28 with Settings

use of org.elasticsearch.common.settings.Settings in project crate by crate.

the class FulltextAnalyzerResolverTest method resolveAnalyzerBuiltinTokenFilter.

@Test
public void resolveAnalyzerBuiltinTokenFilter() throws Exception {
    execute("CREATE ANALYZER builtin_filter (" + "   tokenizer whitespace," + "   token_filters (" + "       ngram WITH (" + "           min_gram=1" + "       )" + "   )" + ")");
    Settings fullAnalyzerSettings = fulltextAnalyzerResolver.resolveFullCustomAnalyzerSettings("builtin_filter");
    assertThat(fullAnalyzerSettings.getAsMap(), allOf(hasEntry("index.analysis.filter.builtin_filter_ngram.type", "ngram"), hasEntry("index.analysis.filter.builtin_filter_ngram.min_gram", "1")));
}
Also used : Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Example 29 with Settings

use of org.elasticsearch.common.settings.Settings in project crate by crate.

the class FulltextAnalyzerResolverTest method resolveAnalyzerWithCharFilters.

@Test
public void resolveAnalyzerWithCharFilters() throws Exception {
    execute("CREATE ANALYZER a3" + "(" + "   tokenizer lowercase," + "   char_filters (" + "       \"html_strip\"," + "       my_mapping WITH (" + "           type='mapping'," + "           mappings=['ph=>f', 'ß=>ss', 'ö=>oe']" + "       )" + "   )" + ")");
    Settings fullAnalyzerSettings = fulltextAnalyzerResolver.resolveFullCustomAnalyzerSettings("a3");
    assertThat(fullAnalyzerSettings.getAsMap(), hasEntry("index.analysis.analyzer.a3.type", "custom"));
    assertThat(fullAnalyzerSettings.getAsMap(), hasEntry("index.analysis.analyzer.a3.tokenizer", "lowercase"));
    assertThat(fullAnalyzerSettings.getAsArray("index.analysis.analyzer.a3.char_filter"), arrayContainingInAnyOrder("html_strip", "a3_my_mapping"));
    assertThat(fullAnalyzerSettings.getAsMap(), hasEntry("index.analysis.char_filter.a3_my_mapping.type", "mapping"));
    assertThat(fullAnalyzerSettings.getAsArray("index.analysis.char_filter.a3_my_mapping" + ".mappings"), arrayContainingInAnyOrder("ph=>f", "ß=>ss", "ö=>oe"));
    execute("CREATE TABLE t1(content " + "string index using fulltext with (analyzer='a3'))");
}
Also used : Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Example 30 with Settings

use of org.elasticsearch.common.settings.Settings in project crate by crate.

the class FulltextAnalyzerResolverTest method useAnalyzerForIndexSettings.

@Test
public void useAnalyzerForIndexSettings() throws Exception {
    execute("CREATE ANALYZER a11 (" + "  TOKENIZER standard," + "  TOKEN_FILTERS (" + "    lowercase," + "    mystop WITH (" + "      type='stop'," + "      stopword=['the', 'over']" + "    )" + "  )" + ")");
    Settings settings = getPersistentClusterSettings();
    assertThat(settings.getAsMap(), allOf(hasKey("crate.analysis.custom.analyzer.a11"), hasKey("crate.analysis.custom.filter.a11_mystop")));
    Settings analyzerSettings = FulltextAnalyzerResolver.decodeSettings(settings.get("crate.analysis.custom.analyzer.a11"));
    Settings tokenFilterSettings = FulltextAnalyzerResolver.decodeSettings(settings.get("crate" + ".analysis.custom.filter.a11_mystop"));
    Settings.Builder builder = Settings.builder();
    builder.put(analyzerSettings);
    builder.put(tokenFilterSettings);
    execute("create table test (" + " id integer primary key," + " name string," + " content string index using fulltext with (analyzer='a11')" + ")");
    ensureYellow();
    execute("insert into test (id, name, content) values (?, ?, ?)", new Object[] { 1, "phrase", "The quick brown fox jumps over the lazy dog." });
    execute("insert into test (id, name, content) values (?, ?, ?)", new Object[] { 2, "another phrase", "Don't panic!" });
    refresh();
    SQLResponse response = execute("select id from test where match(content, 'brown jump')");
    assertEquals(1L, response.rowCount());
    assertEquals(1, response.rows()[0][0]);
}
Also used : SQLResponse(io.crate.testing.SQLResponse) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Aggregations

Settings (org.elasticsearch.common.settings.Settings)866 IndexSettings (org.elasticsearch.index.IndexSettings)112 Path (java.nio.file.Path)91 IOException (java.io.IOException)83 ClusterState (org.elasticsearch.cluster.ClusterState)76 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)72 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)68 HashMap (java.util.HashMap)66 ArrayList (java.util.ArrayList)64 Version (org.elasticsearch.Version)63 Environment (org.elasticsearch.env.Environment)63 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)61 Test (org.junit.Test)60 Map (java.util.Map)55 Index (org.elasticsearch.index.Index)55 Matchers.containsString (org.hamcrest.Matchers.containsString)54 List (java.util.List)45 ThreadPool (org.elasticsearch.threadpool.ThreadPool)40 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)37 MetaData (org.elasticsearch.cluster.metadata.MetaData)36