Search in sources :

Example 1 with HunspellService

use of org.elasticsearch.indices.analysis.HunspellService in project elasticsearch by elastic.

the class HunspellServiceTests method testLocaleDirectoryWithNodeLevelConfig.

public void testLocaleDirectoryWithNodeLevelConfig() throws Exception {
    Settings settings = Settings.builder().put(Environment.PATH_CONF_SETTING.getKey(), getDataPath("/indices/analyze/conf_dir")).put(HUNSPELL_LAZY_LOAD.getKey(), randomBoolean()).put(HUNSPELL_IGNORE_CASE.getKey(), true).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).build();
    Dictionary dictionary = new HunspellService(settings, new Environment(settings), emptyMap()).getDictionary("en_US");
    assertThat(dictionary, notNullValue());
    assertTrue(dictionary.getIgnoreCase());
}
Also used : Dictionary(org.apache.lucene.analysis.hunspell.Dictionary) HunspellService(org.elasticsearch.indices.analysis.HunspellService) Environment(org.elasticsearch.env.Environment) Settings(org.elasticsearch.common.settings.Settings)

Example 2 with HunspellService

use of org.elasticsearch.indices.analysis.HunspellService in project elasticsearch by elastic.

the class HunspellServiceTests method testDicWithTwoAffs.

public void testDicWithTwoAffs() throws Exception {
    Settings settings = Settings.builder().put(Environment.PATH_CONF_SETTING.getKey(), getDataPath("/indices/analyze/two_aff_conf_dir")).put(HUNSPELL_LAZY_LOAD.getKey(), randomBoolean()).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).build();
    IllegalStateException e = expectThrows(IllegalStateException.class, () -> new HunspellService(settings, new Environment(settings), emptyMap()).getDictionary("en_US"));
    assertEquals("failed to load hunspell dictionary for locale: en_US", e.getMessage());
    assertThat(e.getCause(), hasToString(containsString("Too many affix files")));
}
Also used : HunspellService(org.elasticsearch.indices.analysis.HunspellService) Environment(org.elasticsearch.env.Environment) Settings(org.elasticsearch.common.settings.Settings)

Example 3 with HunspellService

use of org.elasticsearch.indices.analysis.HunspellService in project elasticsearch by elastic.

the class HunspellServiceTests method testLocaleDirectoryWithLocaleSpecificConfig.

public void testLocaleDirectoryWithLocaleSpecificConfig() throws Exception {
    Settings settings = Settings.builder().put(Environment.PATH_CONF_SETTING.getKey(), getDataPath("/indices/analyze/conf_dir")).put(HUNSPELL_LAZY_LOAD.getKey(), randomBoolean()).put(HUNSPELL_IGNORE_CASE.getKey(), true).put("indices.analysis.hunspell.dictionary.en_US.strict_affix_parsing", false).put("indices.analysis.hunspell.dictionary.en_US.ignore_case", false).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).build();
    Dictionary dictionary = new HunspellService(settings, new Environment(settings), emptyMap()).getDictionary("en_US");
    assertThat(dictionary, notNullValue());
    assertFalse(dictionary.getIgnoreCase());
    // testing that dictionary specific settings override node level settings
    dictionary = new HunspellService(settings, new Environment(settings), emptyMap()).getDictionary("en_US_custom");
    assertThat(dictionary, notNullValue());
    assertTrue(dictionary.getIgnoreCase());
}
Also used : Dictionary(org.apache.lucene.analysis.hunspell.Dictionary) HunspellService(org.elasticsearch.indices.analysis.HunspellService) Environment(org.elasticsearch.env.Environment) Settings(org.elasticsearch.common.settings.Settings)

Example 4 with HunspellService

use of org.elasticsearch.indices.analysis.HunspellService in project elasticsearch by elastic.

the class HunspellServiceTests method testDicWithNoAff.

public void testDicWithNoAff() throws Exception {
    Settings settings = Settings.builder().put(Environment.PATH_CONF_SETTING.getKey(), getDataPath("/indices/analyze/no_aff_conf_dir")).put(HUNSPELL_LAZY_LOAD.getKey(), randomBoolean()).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).build();
    IllegalStateException e = expectThrows(IllegalStateException.class, () -> new HunspellService(settings, new Environment(settings), emptyMap()).getDictionary("en_US"));
    assertEquals("failed to load hunspell dictionary for locale: en_US", e.getMessage());
    assertThat(e.getCause(), hasToString(containsString("Missing affix file")));
}
Also used : HunspellService(org.elasticsearch.indices.analysis.HunspellService) Environment(org.elasticsearch.env.Environment) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

Settings (org.elasticsearch.common.settings.Settings)4 Environment (org.elasticsearch.env.Environment)4 HunspellService (org.elasticsearch.indices.analysis.HunspellService)4 Dictionary (org.apache.lucene.analysis.hunspell.Dictionary)2