Search in sources :

Example 11 with AnalysisRegistry

use of org.elasticsearch.index.analysis.AnalysisRegistry in project elasticsearch by elastic.

the class AnalysisModuleTests method testVersionedAnalyzers.

public void testVersionedAnalyzers() throws Exception {
    String yaml = "/org/elasticsearch/index/analysis/test1.yml";
    Settings settings2 = Settings.builder().loadFromStream(yaml, getClass().getResourceAsStream(yaml)).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_2_0_0).build();
    AnalysisRegistry newRegistry = getNewRegistry(settings2);
    IndexAnalyzers indexAnalyzers = getIndexAnalyzers(newRegistry, settings2);
    // registry always has the current version
    assertThat(newRegistry.getAnalyzer("default"), is(instanceOf(NamedAnalyzer.class)));
    NamedAnalyzer defaultNamedAnalyzer = (NamedAnalyzer) newRegistry.getAnalyzer("default");
    assertThat(defaultNamedAnalyzer.analyzer(), is(instanceOf(StandardAnalyzer.class)));
    assertEquals(Version.CURRENT.luceneVersion, defaultNamedAnalyzer.analyzer().getVersion());
    // analysis service has the expected version
    assertThat(indexAnalyzers.get("standard").analyzer(), is(instanceOf(StandardAnalyzer.class)));
    assertEquals(Version.V_2_0_0.luceneVersion, indexAnalyzers.get("standard").analyzer().getVersion());
    assertEquals(Version.V_2_0_0.luceneVersion, indexAnalyzers.get("thai").analyzer().getVersion());
    assertThat(indexAnalyzers.get("custom7").analyzer(), is(instanceOf(StandardAnalyzer.class)));
    assertEquals(org.apache.lucene.util.Version.fromBits(3, 6, 0), indexAnalyzers.get("custom7").analyzer().getVersion());
}
Also used : AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) NamedAnalyzer(org.elasticsearch.index.analysis.NamedAnalyzer) IndexAnalyzers(org.elasticsearch.index.analysis.IndexAnalyzers) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 12 with AnalysisRegistry

use of org.elasticsearch.index.analysis.AnalysisRegistry in project elasticsearch by elastic.

the class ESTestCase method createTestAnalysis.

/**
     * Creates an TestAnalysis with all the default analyzers configured.
     */
public static TestAnalysis createTestAnalysis(IndexSettings indexSettings, Settings nodeSettings, AnalysisPlugin... analysisPlugins) throws IOException {
    Environment env = new Environment(nodeSettings);
    AnalysisModule analysisModule = new AnalysisModule(env, Arrays.asList(analysisPlugins));
    AnalysisRegistry analysisRegistry = analysisModule.getAnalysisRegistry();
    return new TestAnalysis(analysisRegistry.build(indexSettings), analysisRegistry.buildTokenFilterFactories(indexSettings), analysisRegistry.buildTokenizerFactories(indexSettings), analysisRegistry.buildCharFilterFactories(indexSettings));
}
Also used : AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) Environment(org.elasticsearch.env.Environment) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) AnalysisModule(org.elasticsearch.indices.analysis.AnalysisModule)

Example 13 with AnalysisRegistry

use of org.elasticsearch.index.analysis.AnalysisRegistry in project elasticsearch by elastic.

the class IndexModuleTests method testAddIndexOperationListener.

public void testAddIndexOperationListener() throws IOException {
    IndexModule module = new IndexModule(IndexSettingsModule.newIndexSettings(index, settings), new AnalysisRegistry(environment, emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()));
    AtomicBoolean executed = new AtomicBoolean(false);
    IndexingOperationListener listener = new IndexingOperationListener() {

        @Override
        public Engine.Index preIndex(ShardId shardId, Engine.Index operation) {
            executed.set(true);
            return operation;
        }
    };
    module.addIndexOperationListener(listener);
    expectThrows(IllegalArgumentException.class, () -> module.addIndexOperationListener(listener));
    expectThrows(IllegalArgumentException.class, () -> module.addIndexOperationListener(null));
    IndexService indexService = newIndexService(module);
    assertEquals(2, indexService.getIndexOperationListeners().size());
    assertEquals(IndexingSlowLog.class, indexService.getIndexOperationListeners().get(0).getClass());
    assertSame(listener, indexService.getIndexOperationListeners().get(1));
    ParsedDocument doc = InternalEngineTests.createParsedDoc("1", "test", null);
    Engine.Index index = new Engine.Index(new Term("_uid", doc.uid()), doc);
    ShardId shardId = new ShardId(new Index("foo", "bar"), 0);
    for (IndexingOperationListener l : indexService.getIndexOperationListeners()) {
        l.preIndex(shardId, index);
    }
    assertTrue(executed.get());
    indexService.close("simon says", false);
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IndexingOperationListener(org.elasticsearch.index.shard.IndexingOperationListener) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) Term(org.apache.lucene.index.Term) Engine(org.elasticsearch.index.engine.Engine)

Example 14 with AnalysisRegistry

use of org.elasticsearch.index.analysis.AnalysisRegistry in project elasticsearch by elastic.

the class IndexModuleTests method testSetupWithoutType.

public void testSetupWithoutType() throws IOException {
    Settings indexSettings = Settings.builder().put("index.similarity.my_similarity.foo", "bar").put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
    IndexModule module = new IndexModule(IndexSettingsModule.newIndexSettings("foo", indexSettings), new AnalysisRegistry(environment, emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()));
    Exception ex = expectThrows(IllegalArgumentException.class, () -> newIndexService(module));
    assertEquals("Similarity [my_similarity] must have an associated type", ex.getMessage());
}
Also used : AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) Settings(org.elasticsearch.common.settings.Settings) ScriptSettings(org.elasticsearch.script.ScriptSettings) AlreadySetException(org.apache.lucene.util.SetOnce.AlreadySetException) EngineException(org.elasticsearch.index.engine.EngineException) IOException(java.io.IOException)

Example 15 with AnalysisRegistry

use of org.elasticsearch.index.analysis.AnalysisRegistry in project elasticsearch by elastic.

the class IndexModuleTests method testListener.

public void testListener() throws IOException {
    Setting<Boolean> booleanSetting = Setting.boolSetting("index.foo.bar", false, Property.Dynamic, Property.IndexScope);
    IndexModule module = new IndexModule(IndexSettingsModule.newIndexSettings(index, settings, booleanSetting), new AnalysisRegistry(environment, emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()));
    Setting<Boolean> booleanSetting2 = Setting.boolSetting("index.foo.bar.baz", false, Property.Dynamic, Property.IndexScope);
    AtomicBoolean atomicBoolean = new AtomicBoolean(false);
    module.addSettingsUpdateConsumer(booleanSetting, atomicBoolean::set);
    try {
        module.addSettingsUpdateConsumer(booleanSetting2, atomicBoolean::set);
        fail("not registered");
    } catch (IllegalArgumentException ex) {
    }
    IndexService indexService = newIndexService(module);
    assertSame(booleanSetting, indexService.getIndexSettings().getScopedSettings().get(booleanSetting.getKey()));
    indexService.close("simon says", false);
}
Also used : AnalysisRegistry(org.elasticsearch.index.analysis.AnalysisRegistry) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Aggregations

AnalysisRegistry (org.elasticsearch.index.analysis.AnalysisRegistry)21 Settings (org.elasticsearch.common.settings.Settings)13 ScriptSettings (org.elasticsearch.script.ScriptSettings)7 IndexSettings (org.elasticsearch.index.IndexSettings)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 IOException (java.io.IOException)4 IndexAnalyzers (org.elasticsearch.index.analysis.IndexAnalyzers)4 AlreadySetException (org.apache.lucene.util.SetOnce.AlreadySetException)3 EngineException (org.elasticsearch.index.engine.EngineException)3 AssertingDirectoryReader (org.apache.lucene.index.AssertingDirectoryReader)2 Term (org.apache.lucene.index.Term)2 BM25Similarity (org.apache.lucene.search.similarities.BM25Similarity)2 Similarity (org.apache.lucene.search.similarities.Similarity)2 Environment (org.elasticsearch.env.Environment)2 NamedAnalyzer (org.elasticsearch.index.analysis.NamedAnalyzer)2 DisabledQueryCache (org.elasticsearch.index.cache.query.DisabledQueryCache)2 Engine (org.elasticsearch.index.engine.Engine)2 ParsedDocument (org.elasticsearch.index.mapper.ParsedDocument)2 IndexingOperationListener (org.elasticsearch.index.shard.IndexingOperationListener)2 ShardId (org.elasticsearch.index.shard.ShardId)2